Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Script: example_query_accesslog.py
import accesslog_parse_mongo
import sys
from datetime import datetime, timedelta
def main():
(mongo_connection, mongo_db, mongo_collection) = \
accesslog_parse_mongo.do_mongo_init()
# Get time > now()-1day and url=sys.argv[1]
if len(sys.argv) > 1:
query = {'timestamp': {'$gt': datetime.now() - timedelta(days=1)},
'url': sys.argv[1]}
else:
query = {'timestamp': {'$gt': datetime.now() - timedelta(days=1)}}
entries = mongo_collection.find(query, )
print "There are %i visits from:" % entries.count()
for entry in entries:
print " - %s at %s from %s" % \
(entry['client_ip'], entry['time'], entry['referer'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment