add seconds of today

This commit is contained in:
Wolfgang Hottgenroth 2015-06-08 22:09:58 +02:00
parent 3e66326583
commit 13f95077d3

View File

@ -11,11 +11,15 @@ import datetime
def on_message(client, userdata, msg):
j = json.loads(msg.payload)
now = datetime.datetime.now()
midnight = now.replace(now.year, now.month, now.day, 0,0,0,0)
seconds = (now - midnight).seconds
j['metadata']['timestamp'] = datetime.datetime.now()
j['metadata']['seconds'] = seconds
print(j)
mongoClient = pymongo.MongoClient('localhost')
db = mongoClient.iot
r = db.iot.insert(j)
r = db.iot.insert_one(j)
if __name__ == '__main__':