Author: poeml Date: Tue Dec 15 00:55:09 2009 New Revision: 52 URL: http://svn.mirrorbrain.org/viewvc/mod_stats?rev=52&view=rev Log: first shot on creating objects in a database and increasing counters Modified: trunk/tools/dlcount.py Modified: trunk/tools/dlcount.py URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/tools/dlcount.py?rev=52&r1=51&r2=52&view=diff ============================================================================== --- trunk/tools/dlcount.py (original) +++ trunk/tools/dlcount.py Tue Dec 15 00:55:09 2009 _at_@ -63,9 +63,11 @@ import sys import os +import os.path import re import hashlib import time +from datetime import datetime from optparse import OptionParser try: _at_@ -321,6 +323,7 @@ matched = mreg if not matched: yield rq + continue # apply postfiltering for r, s, mreg in conf['statspostfilter']: _at_@ -344,6 +347,10 @@ parser = OptionParser(usage=usage, version=version) #parser.disable_interspersed_args() + parser.add_option('--db', + action="store_true", dest="db", default=False, + help="save counts to the database") + parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, help="print only errors") _at_@ -370,9 +377,36 @@ reqs = gen_fragments(loglines, conf['statslogmask'][0][0]) items = gen_processreqs(reqs, conf) + + if options.db: + dirpath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + sys.path.insert(0, dirpath) + os.environ['DJANGO_SETTINGS_MODULE'] = 'downloadstats.settings' + from downloadstats.stats.models import Counter + + #counters = Counter.objects.all() + #for i in counters: + # print i + for item in items: if item.countable: - print item.country, item.url + #print item.country, item.url + (product, osname, version, lang) = item.url.split() + + # d = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(event_epoch)) + d = datetime(item.tstamp[0], item.tstamp[1], item.tstamp[2]) + #print d, (product, osname, version, lang), item.country + if options.db: + c, created = Counter.objects.get_or_create(date=d, + product=product, osname=osname, version=version, lang=lang, + country=item.country) + if created: + # count is 1 for a new item + pass + else: + # item existed already - increase its counter + c.count += 1 + c.save() sys.exit(0) _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Mon Dec 14 2009 - 23:55:13 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT