Skip to content

Instantly share code, notes, and snippets.

@ericdill
Created February 12, 2015 20:27
Show Gist options
  • Save ericdill/cccadfe4e5f2aec87a6d to your computer and use it in GitHub Desktop.
Save ericdill/cccadfe4e5f2aec87a6d to your computer and use it in GitHub Desktop.
Adding datetimes back into BrokerStruct objects
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