In [160]:
from pymongo import MongoClient
import datetime
from collections import defaultdict
since_str = "2016-07-15 16:56:41.129122"
since = datetime.datetime.strptime(since_str, "%Y-%m-%d %H:%M:%S.%f")
start_time = datetime.datetime(2016, 7, 15, 10, 30, 0)
# end_time =   datetime.datetime(2016, 7, 15, 10, 41, 40)
end_time = datetime.datetime.utcnow()

client = MongoClient('mongodb://172.16.20.181:27017/')
# client = MongoClient('mongodb://localhost:27017/')
db = client.kinesis_traffic
job_summaries = db.job_summaries
summaries = job_summaries.find({"$and":
    [{"date_added" : {"$gte": since }},
    {"date_added" : {"$lte": end_time }}]
})
aggdict = defaultdict(int)
event_count = 0
print("\nJOBS INCLUDED\n")
for summary in summaries:
    print(summary["job_name"], summary["event_type"], summary["date_added"])
    client_id_dict = summary['client_id_dict']
    for key in client_id_dict.keys():
        aggdict[key] += client_id_dict[key]
        event_count += client_id_dict[key]
print("\nEVENTS COUNT {}\n".format(event_count))
print("\nEvents Per Client ID\n")
print("ID\t#\n")
for key, val in aggdict.items():
    print("{}\t{}".format(key, val))


JOBS INCLUDED


EVENTS COUNT 0


Events Per Client ID

ID	#


In [12]:
from datetime import datetime
print(datetime.utcnow())
print(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f000'))


2016-07-19 18:51:13.201081
2016-07-19 18:51:13.201216000