if s['body']['planned_timestamp'] == '':
planned_timestamp = None
else:
planned_timestamp = str(datetime.datetime.fromtimestamp(float(s['body']['planned_timestamp'])/1000)) #Formats data into DD/MM/YYYY HH:MM:SSif s['body']['planned_timestamp'] == '':
planned_timestamp = None
else:
onehourforward = s['body']['planned_timestamp'] - timedelta(hours=1)
planned_timestamp = str(datetime.datetime.fromtimestamp(float(onehourforward)/1000))Hi Waihun
The planned timestamp is presented as a string, and you can only use timedelta against a datetime. So you’ll need to adjust your code as a hybrid between the two closer to something similar to
datetime.datetime.fromtimestamp(float(s['body']['planned_timestamp'])/1000) – timedelta(hours=1)
Obviously you’ll need to take your timestamp from there and also do some management around it given that it changes when UK is in GMT, etc, but that’s the base issue
Tom
--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
openraildata-t...@googlegroups.com.
To post to this group, send email to
openrail...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to openrail...@googlegroups.com.
Hi Wailun (sorry I misread your name first time!)
I’ve quickly just mocked this together on a Python terminal and it seems to work OK
>>> from datetime import datetime
>>> from datetime import timedelta
>>> timestamp_str = '1556712998000'
>>> datetime.fromtimestamp(int(timestamp_str) / 1000)
datetime.datetime(2019, 5, 1, 13, 16, 38)
>>> datetime.fromtimestamp(int(timestamp_str) / 1000) - timedelta(hours=1)
datetime.datetime(2019, 5, 1, 12, 16, 38)
I have a feeling that the minus sign might have been broken by encoding and it becoming a hyphen or similar so try just rewriting the line.
Tom
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-t...@googlegroups.com.