def handle(self, force, *args, **options): mapper = UAMapper() if self.fetch_latest_wurfl() or force: self.wurfl_to_python() from wurfl import devices print "Updating Redis..." for i, ua in enumerate(devices.uas): device = devices.select_ua(ua) mapper.map(user_agent=ua, device=device) print "Done." else: print "Done. Redis unchanged."
def get_device(request): """ Uses pywurfl to detect the requesting device from the HTTP_USER_AGENT string, and adds it to the context with the variable name `device`. If the device is not found by pywurfl, it sets the context variable to None. """ ua = request.META['HTTP_USER_AGENT'] try: device = devices.select_ua(ua, search=algorithm(), filter_noise=True) except DeviceNotFound, e: device = None
def device(self): """Look up the device profile based on the UA and cache it on the request object. """ global _ua_device_cache ua = unicode(self.user_agent) if "HTTP_X_OPERAMINI_PHONE_UA" in self.environ: # Opera mini proxy specia case ua = unicode(self.environ["HTTP_X_OPERAMINI_PHONE_UA"]) if ua not in _ua_device_cache: search_algorithm = TwoStepAnalysis(devices) _ua_device_cache[ua] = devices.select_ua(ua, search=search_algorithm) return _ua_device_cache[ua]
def detectMobileByUA(self,user_agent): search_algorithm = TwoStepAnalysis(devices) device = devices.select_ua(unicode(user_agent), search=search_algorithm) print device
ua5 = u'Mozilla/5.0 (Linux; ABC 4.4.4; XXXX Build/18.1.A.2.25) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36' ua6 = u'Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/KRT16M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36' ua7 = u'Mozilla/5.0 (Linux; Android 4.4.2; SM701 Build/SANFRANCISCO) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36' ua7 = u'Mozilla/5.0 (Linux; U; Android 2.3.6; pt-br; GT-I9070 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML like Gecko) Version/4.0 Mobile Safari/533.1' ua7 = u'Mozilla/5.0 (Linux; U; Android 4.1.2; pt-br; GT-S6812B Build/JZO54K) AppleWebKit/534.30 (KHTML like Gecko) Version/4.0 Mobile Safari/534.30' ua7 = u'Mozilla/5.0 (Linux; U; Android 4.1.2; pt-br; GT-P3110 Build/JZO54K) AppleWebKit/534.30 (KHTML like Gecko) Version/4.0 Safari/534.30' search_algorithm = TwoStepAnalysis(devices) # Print out the specialized capabilities for this device. #print device before = time.time() l = [ua1, ua2, ua3, ua4, ua5, ua6, ua7] for i in l: device = devices.select_ua(i, search=search_algorithm) print '-'*50 print 'is_wireless_device: ', device.is_wireless_device print 'model_name: ', device.model_name print 'brand_name: ', device.brand_name print 'devid: ', device.devid print 'devua: ', device.devua print 'device_os: ', device.device_os print 'device_os_version: ', device.device_os_version print 'mobile_browser: ', device.mobile_browser print 'mobile_browser_version: ', device.mobile_browser_version print 'mobileoptimized: ', device.mobileoptimized diff = (time.time() - before)*1000
#!/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)