Skip to content

Commit 370a350

Browse files
committed
Replacing timestamp with datetime in showing the log file
1 parent 8ecfe4d commit 370a350

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

freemyip.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
from urllib.request import urlopen
66
from requests import get
7+
from datetime import datetime
78
import csv
89
import re
910
import time
@@ -114,9 +115,12 @@ def print_log(log_file):
114115
except IOError:
115116
print('Error: The log file [{}] could not be opened.'.format(log_file))
116117
exit()
117-
output += "\nDomain \t\t\t\t\t IP \t\t\t Timestamp\n"
118+
output += "\nDomain \t\t\t\t\t IP \t\t\t Datetime\n"
118119
for line in f:
119-
output += line.replace(',',' \t\t').replace(' ','\t')
120+
timestamp = re.search('[+-]?([0-9]*[.])?[0-9]+$',line).group()
121+
ts = float(timestamp)
122+
dt = datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
123+
output += line.replace(',',' \t\t').replace(' ','\t').replace(timestamp+'\n',dt+'\n')
120124

121125
f.close()
122126
output += '===== \nShow log is finished.'

0 commit comments

Comments
 (0)