I have a function that I call which generates a timestamp on a event that comes through a For loop.
Function, and RAW timestamp
def atimer ():
timenow = time.time()
return(timenow)
print timenow
1434615010.27858
The timestamp looks like this "1434615010.27858", which is nice and small for database use in sqlite3. When I convert the timestamp using datetime I get a proper statement of time(see below)..
Converted
>>> print datetime.datetime.fromtimestamp(1434615010.27858)
2015-06-18 10:10:10.278580
The issue with this extremely efficient problem is that I have a influx of events that show up as the below timestamp printout.
2015-06-18 11:36:57.830000
2015-06-18 11:36:57.830000
2015-06-18 11:36:57.830000
2015-06-18 11:36:59.340000
2015-06-18 11:36:59.340000
2015-06-18 11:36:59.340000
2015-06-18 11:37:00.740000
2015-06-18 11:37:00.740000
2015-06-18 11:37:00.740000
2015-06-18 11:37:02.130000
I would like to compare the timestamps with each other and then only submit the first one in that given minute to the database (SQL UPDATE).
Question> Is Regex my only option here or can I tone this timestamp itself down to not give me such a detailed timestamp?
Info: The main reason I have chosen this timestamp was that it's small and takes up less space in the DB, especially when you work with 1000's of them.
Below is the output I'm trying to get at...
2015-06-18 11:36
2015-06-18 11:37
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire