Skip to content

Instantly share code, notes, and snippets.

@gravesm
Last active December 28, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravesm/7489580 to your computer and use it in GitHub Desktop.
Save gravesm/7489580 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import fileinput
import json
from datetime import datetime
import time
from pymongo import MongoClient
def get_collection(conn=None):
client = MongoClient(conn)
return client.oastats.requests
def main(collection):
for line in fileinput.input():
request = json.loads(line)
t = time.strptime(request['time'], "%Y-%m-%dT%H:%M:%S")
request['time'] = datetime.fromtimestamp(time.mktime(t))
collection.insert(request)
if __name__ == '__main__':
collection = get_collection()
main(collection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment