def s3_populate_browser_compatibility(request): """ Use WURFL for browser compatibility detection @ToDo: define a list of features to store """ features = Storage( #category = ["list","of","features","to","store"] ) try: from pywurfl.algorithms import TwoStepAnalysis except ImportError: s3_debug( "pywurfl python module has not been installed, browser compatibility listing will not be populated. Download pywurfl from http://pypi.python.org/pypi/pywurfl/" ) return False import wurfl device = wurfl.devices.select_ua(unicode(request.env.http_user_agent), search=TwoStepAnalysis(wurfl.devices)) browser = Storage() #for feature in device: #if feature[0] not in category_list: #category_list.append(feature[0]) #for category in features: #if category in #browser[category] = Storage() for feature in device: if feature[0] in features and \ feature[1] in features[feature[0]]: browser[feature[0]][feature[1]] = feature[2] return browser
def _analyze(ua_str): return devices.select_ua(ua_str, search=TwoStepAnalysis(devices))
#!/usr/bin/env python import sys from wurfl import devices from pywurfl.algorithms import TwoStepAnalysis search_algorithm = TwoStepAnalysis(devices) # input comes from STDIN (standard input) for line in sys.stdin: # remove leading and trailing whitespace line = line.strip() # split the line into words words = line.split(" ") # increase counters # for word in words: # write the results to STDOUT (standard output); # what we output here will be the input for the # Reduce step, i.e. the input for reducer.py # # tab-delimited; the trivial word count is 1 user_agent = unicode(words[len(words) - 1]) device = devices.select_ua(user_agent, search=search_algorithm) print '%s %s (%s %s)\t%s' % (device.brand_name, device.model_name, device.mobile_browser, device.mobile_browser_version, 1)