Skip to content

Instantly share code, notes, and snippets.

@jplsightm
Created May 15, 2017 15:48
Show Gist options
  • Save jplsightm/5085219a35dd7705139a2c2d453224bf to your computer and use it in GitHub Desktop.
Save jplsightm/5085219a35dd7705139a2c2d453224bf to your computer and use it in GitHub Desktop.
Updating timestamps in the site machine platform
# 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