selwin / python-user-agents

A Python library that provides an easy way to identify devices like mobile phones, tablets and their capabilities by parsing (browser) user agent strings.
MIT License
1.42k stars 196 forks source link

Firefox OS issues #6

Open miketaylr opened 10 years ago

miketaylr commented 10 years ago

Hi there. There's currently some problems with parsing Firefox OS ua strings:

Firefox OS Mobile:

>>> ua_string = 'Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0'
>>> b = parse(ua_string)
>>> b.device
Device(family='Other')
>>> b.browser
Browser(family=u'Firefox Mobile', version=(26,), version_string='26')
>>> b.is_tablet
False
>>> b.is_mobile
False
>>> b.is_touch_capable
False
>>> b.os
OperatingSystem(family=u'Firefox OS', version=(), version_string='')

is_mobile and is_touch_capable should be true.

Firefox OS for tablets:

>>> ua_string = 'Mozilla/5.0 (Tablet; rv:29.0) Gecko/29.0 Firefox/29.0'
>>> b = parse(ua_string)
>>> b.is_mobile
False
>>> b.is_touch_capable
False
>>> b.is_tablet
False
>>> b.os
OperatingSystem(family='Other', version=(), version_string='')
>>> b.device
Device(family='Other')

is_mobile and is_touch_capable should be true. os.family should report Firefox OS -- I've made a pull request against ua-parser for that though: https://github.com/tobie/ua-parser/pull/331

karlcow commented 10 years ago

I'm happy to provide a patch. Not today. but next week.

selwin commented 10 years ago

@karlcow thanks for the offer :). Let's hope that https://github.com/tobie/ua-parser/pull/331 gets merged soon.

karlcow commented 10 years ago

Oh. Indeed you have a dependency on @tobie library. Understood aand @miketaylr already did a patch there.

from ua_parser import user_agent_parser
karlcow commented 8 years ago

This can be closed as FIXED.

>>> # Accessing user agent's browser attributes
... user_agent.browser  
Browser(family='Firefox Mobile', version=(44,), version_string='44')
>>> user_agent.browser.family  
'Firefox Mobile'
>>> user_agent.browser.version 
(44,)
>>> user_agent.browser.version_string
'44'
>>> 
>>> # Accessing user agent's operating system properties
... user_agent.os  
OperatingSystem(family='Firefox OS', version=(), version_string='')
>>> user_agent.os.family  
'Firefox OS'
>>> user_agent.os.version 
()
>>> user_agent.os.version_string
''
>>> 
>>> # Accessing user agent's device properties
... user_agent.device  
Device(family='Generic Smartphone', brand='Generic', model='Smartphone')
>>> user_agent.device.family 
'Generic Smartphone'
>>> user_agent.device.brand 
'Generic'
>>> user_agent.device.model
'Smartphone'
>>> 
>>> # Viewing a pretty string version
... str(user_agent)
'Generic Smartphone / Firefox OS / Firefox Mobile 44'
>>> user_agent.is_touch_capable
False
>>> user_agent.is_tablet
False
>>> user_agent.is_mobile
True
>>> 

maybe apart the is_touch_capable

karlcow commented 8 years ago

Not sure why btw https://github.com/selwin/python-user-agents/blob/master/user_agents/parsers.py#L58-L66

karlcow commented 8 years ago

Just an old version.

>>> import user_agents
>>> user_agents.VERSION
(0, 3, 2)

Let's close it as Fixed.