Python Forum
How to compare timestamps in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare timestamps in python
#1
I have just playing with python , I am stuck for the following problem :

file1 :
Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28 2018

Bootstrapping registry and package to current versions...done
statement ERR-2001: table is corrupt check for cause

could not determine the current status.

Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:58 2018

file2 :

LOG file opened at 02/03/18 01:11:05

DUP-05004: statement1
DUP-05007: statement2


LOG file opened at 02/03/18 01:11:14

DUP-05004: statement1

DUP-05007: statement2


LOG file opened at 02/23/18 01:10:33

DUP-05004: statement1

DUP-05007: statement2

I need to look for the ERR-2001 in file1 if it matches then go to file2 and print the message nearest to the timestamp found in file1 within two minutes of range .


1) What regex I use get the timestamp from file 1 and then file 2 ?

2) How to I acheive
so in this case file1 Start: Fri Feb 23 01:10:28 2018
End time : Fri Feb 23 01:10:58 2018
check in file 2 nearest to file1 end time : 02/23/18 01:10:33
Reply
#2
I would just make a simple regex to get potential time stamps, and then check them by trying to convert them to datetime objects from the datetime module. Then you can compare the difference of the datetime objects with a timedelta object.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Hi all ,

I tried the following regex :

x = re.findall ( "([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4})", st )
print x
[('Feb ', '23 01:10:28 2018', ':28'), ('Feb ', '23 01:10:36 2018', ':36')]

print x[0][1]

23 01:10:28 2018

y = datetime.datetime.strptime ( x[0][1], '%d %H:%M:%S %y')
ValueError: unconverted data remains: 18
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find tags using specific text (timestamps) in a url? q988988 1 1,368 Mar-08-2022, 08:09 AM
Last Post: buran
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,601 Oct-09-2021, 03:30 PM
Last Post: Larz60+
  Speech Recognition with timestamps DeanAseraf1 3 6,563 Jun-27-2021, 06:58 PM
Last Post: gh_ad
Bug Help on Flagging Timestamps Daring_T 2 1,857 Oct-28-2020, 08:11 PM
Last Post: Daring_T
  how to compare two different size images in python and find corresponding pixel value squidsirymchenry 1 4,556 Feb-03-2020, 06:48 AM
Last Post: michael1789
  How to compare in python an input value with an hashed value in mysql table? Formationgrowthhacking 4 3,318 Jan-14-2020, 11:43 AM
Last Post: Formationgrowthhacking
  Compare two images with Python is possible? Delemir78 3 4,773 Dec-17-2019, 09:03 PM
Last Post: Larz60+
  How can I compare Python XML-Files and add missing values from one to another kirat 2 2,671 Aug-30-2019, 12:17 PM
Last Post: perfringo
  Python csv compare two file, update value if two value is matched kinojom 1 2,532 Apr-17-2019, 10:36 AM
Last Post: DeaD_EyE
  Compare words Python xSphere 3 2,592 Jan-24-2019, 10:52 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020