Index: trunk/tools/editor_trends/code-snippets/browserstats.py |
— | — | @@ -0,0 +1,55 @@ |
| 2 | +#!/usr/bin/python
|
| 3 | +# -*- coding: utf-8 -*-
|
| 4 | +'''
|
| 5 | +Copyright (C) 2010 by Diederik van Liere (dvanliere@gmail.com)
|
| 6 | +This program is free software; you can redistribute it and/or
|
| 7 | +modify it under the terms of the GNU General Public License version 2
|
| 8 | +as published by the Free Software Foundation.
|
| 9 | +This program is distributed in the hope that it will be useful,
|
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 12 | +See the GNU General Public License for more details, at
|
| 13 | +http://www.fsf.org/licenses/gpl.html
|
| 14 | +'''
|
| 15 | +
|
| 16 | +
|
| 17 | +__author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
|
| 18 | +__author__email = 'dvanliere at gmail dot com'
|
| 19 | +__date__ = '2011-02-10'
|
| 20 | +__version__ = '0.1'
|
| 21 | +
|
| 22 | +import sys
|
| 23 | +sys.path.append('../libs/')
|
| 24 | +
|
| 25 | +from wurfl import devices
|
| 26 | +from pywurfl.algorithms import TwoStepAnalysis
|
| 27 | +
|
| 28 | +try:
|
| 29 | + import psyco
|
| 30 | + psyco.full()
|
| 31 | +except ImportError:
|
| 32 | + pass
|
| 33 | +
|
| 34 | +fh = open('../deployment/india.log-20110209', 'r')
|
| 35 | +search_algorithm = TwoStepAnalysis(devices)
|
| 36 | +
|
| 37 | +phones = {}
|
| 38 | +
|
| 39 | +for line in fh:
|
| 40 | + line = line.split(' ')
|
| 41 | + if len(line) != 14:
|
| 42 | + continue
|
| 43 | + browser = line[13]
|
| 44 | + browser = browser.replace('%', ' ')
|
| 45 | + browser = unicode(browser)
|
| 46 | + device = devices.select_ua(browser, search=search_algorithm)
|
| 47 | + if not device.devid == 'generic_web_browser' and not device.devid == 'generic' and not device.devid == 'generic_web_crawler':
|
| 48 | + #print device.devid, device.devua, device.device_os
|
| 49 | + phones.setdefault(device.devid, 0)
|
| 50 | + phones[device.devid] += 1
|
| 51 | +
|
| 52 | +for phone in phones:
|
| 53 | + print phone, phones[phone]
|
| 54 | +
|
| 55 | +fh.close()
|
| 56 | +
|