Created
February 12, 2015 20:27
-
-
Save ericdill/cccadfe4e5f2aec87a6d to your computer and use it in GitHub Desktop.
Adding datetimes back into BrokerStruct objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
# get the time | |
time = self.time | |
try: | |
# get the timestamp represented as datetime | |
time_as_datetime = getattr(mongo_document, 'time_as_datetime') | |
except AttributeError: | |
# convert the timestamp into a datetime object | |
time_as_datetime = datetime.datetime.fromtimestamp(time) | |
# and set the object attribute | |
setattr(self, 'time_as_datetime', time_as_datetime) | |
except AttributeError: | |
# in some sort of recursion... not in a document with time, ignore | |
# the time issue | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment