Created
May 15, 2017 15:48
-
-
Save jplsightm/5085219a35dd7705139a2c2d453224bf to your computer and use it in GitHub Desktop.
Updating timestamps in the site machine platform
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
# coding: utf-8 | |
# In[12]: | |
import pymongo | |
from datetime import timedelta | |
# In[4]: | |
client = pymongo.MongoClient() | |
# In[9]: | |
t = 'tenant' | |
db = client[t] | |
# In[10]: | |
sslog = db.sslog | |
# In[11]: | |
sslog.count() | |
# In[13]: | |
def sslog_timestamp_fix(rs, collection, offset): | |
slogs = [] | |
for a in rs: | |
a['data']['timestamp'] = a['data']['timestamp'] + timedelta(hours=offset) | |
slogs.append(a) | |
collection.remove({}) | |
for r in slogs: | |
collection.insert_one(r) | |
# In[14]: | |
sslogs = sslog.find({}) | |
# In[15]: | |
sslog_timestamp_fix(sslogs, sslog, 14) | |
# In[ ]: | |
sslog.count() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment