1

log_input.log

1949,1603441909,984159,0.002608,19.8829994202,0.0,640.0
950,1603441910,  416274
21,160340, 24666082,0.002608,19.81913,0.0,638.0

Check the column consistency, disregard the row if the column number are not consistent. Read the second column and convert the second column into local time format.

log_output.log

1949, 10-31-49,984159,0.002608,19.8829994202,0.0,640.0
21, 9-32-20, 24666082,0.002608,19.81913,0.0,638.0

Code:

with open('log_input.txt', 'r') as f:
    csv_data = csv.reader(f)
    csv_lines = list(csv_data)

for line in csv_lines:
  line[1] = convert(line[1].split(':')[1].strip())


Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
Roujri
  • 125
  • 1
  • 7
  • seconds since the epoch -> "readable date" basically described in [Converting unix timestamp string to readable date](https://stackoverflow.com/q/3682748/10197418) – FObersteiner May 06 '21 at 06:48

1 Answers1

2

You can convert epoch to a date using datetime with:

time.strftime('%Y-%m-%d', time.localtime(<your epoch>))

In case it is less than a day, just check if it is less than 86400, and if yes, write as-is.

Duhon
  • 101
  • 5