Git Product home page Git Product logo

device_detector's People

Contributors

adq avatar alexeypetroff avatar anatoliifetisov avatar chedidelias avatar deepsourcebot avatar findus23 avatar thinkwelltwd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

device_detector's Issues

Problem with parsed data object after parsing the same user agent

In [1]: from device_detector import DeviceDetector

In [2]: user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.3 
   ...: 6 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'

In [3]: result1 = DeviceDetector(user_agent).parse()

In [4]: result1.client.engine()
Out[4]: 'WebKit'

In [5]: result2 = DeviceDetector(user_agent).parse()

In [6]: result2.client.engine()
---------------------------------------------------------------------------       
AttributeError                            Traceback (most recent call last)       
<ipython-input-6-ac90275beaa1> in <module>
----> 1 result2.client.engine()

AttributeError: 'NoneType' object has no attribute 'engine'

In [7]: user_agent2 = user_agent + '1'

In [8]: result3 = DeviceDetector(user_agent2).parse()

In [9]: result3.client.engine()
Out[9]: 'WebKit'

If i parse the same user_agent again the "client" object is None

Python 3.7.7
device_detector=0.9.0

Getting `look-behind requires fixed-width pattern` error

I'm getting look-behind requires fixed-width pattern error when literally trying to run the example in the README.

My current Python version is 3.6.8 and my code looks something like this:

from device_detector import DeviceDetector

ua = 'Mozilla/5.0 (Linux; Android 4.3; C5502 Build/10.4.1.B.0.101) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'

device = DeviceDetector(ua).parse()

So, exactly like in the example. The only thing I can think of is the Python version, any idea why this could be colliding somehow?

I can provide a full stacktrace, but the relevant places seem to be:

.venv/lib/python3.6/site-packages/device_detector/parser/parser.py in _parse
73. for ua_data in self.regex_list:

.venv/lib/python3.6/site-packages/device_detector/yaml_loader.py in regex_list
69. regex['regex'] = re.compile(BOUNDED_REGEX.format(regex['regex']), re.IGNORECASE)

I will update my virtualenv with a new python version, just to see what happens. I'll keep you posted

Encoding problems on Windows computers

On version 0.9 worked ok, but on 0.10 i have a following exception when i try to parse user_agent string (the "x" variable):

In [1]: x = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 
   ...:  like Gecko) Chrome/83.0.4103.61 Safari/537.36'

In [2]: from device_detector import DeviceDetector

In [3]: result1 = DeviceDetector(x).parse()
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)       
<ipython-input-3-55b0fb999d44> in <module>
----> 1 result1 = DeviceDetector(x).parse()

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\device_detector.py in parse(self)
    231 
    232         if not self.skip_bot_detection:
--> 233             self.parse_bot()
    234             if self.is_bot():
    235                 return self.set_parse_cache()

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\device_detector.py in parse_bot(self)
    310         """
    311         if not self.skip_bot_detection and not self.bot:
--> 312             self.bot = Bot(self.user_agent, self.ua_hash, self.ua_spaceless).parse()
    313             self.all_details['bot'] = self.bot.ua_data
    314

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\parser\parser.py in parse(self)
     85             return self
     86
---> 87         self._parse()
     88         self.extract_details()
     89 

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\parser\parser.py in _parse(self)
     69     def _parse(self) -> None:
     70         """Override on subclasses if custom parsing is required"""
---> 71         for ua_data in self.regex_list:
     72             match = self._check_regex(ua_data['regex'])
     73             if match:

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\yaml_loader.py in regex_list(self)
     79
     80         for fixture in self.fixture_files:
---> 81             regexes.extend(self.yaml_to_list('regexes/{}'.format(fixture)))
     82
     83         for regex in regexes:

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\yaml_loader.py in yaml_to_list(self, yfile)
     61         Load yaml file to list of dicts
     62         """
---> 63         regexes = self.load_from_yaml(yfile)
     64         if isinstance(regexes, list):
     65             return regexes

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\device_detector\yaml_loader.py in load_from_yaml(yfile)
     33         if Path('{}/{}'.format(ROOT, yfile)).exists():
     34             with open('{}/{}'.format(ROOT, yfile), 'r') as yf:
---> 35                 return yaml.load(yf, SafeLoader)
     36
     37         try:

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\yaml\__init__.py in load(stream, Loader)
    112     loader = Loader(stream)
    113     try:
--> 114         return loader.get_single_data()
    115     finally:
    116         loader.dispose()

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\site-packages\yaml\constructor.py in get_single_data(self)
     47     def get_single_data(self):
     48         # Ensure that the stream contains a single document and construct 
it.
---> 49         node = self.get_single_node()
     50         if node is not None:
     51             return self.construct_document(node)

ext\_yaml.pyx in _yaml.CParser.get_single_node()

ext\_yaml.pyx in _yaml.CParser._compose_document()

ext\_yaml.pyx in _yaml.CParser._compose_node()

ext\_yaml.pyx in _yaml.CParser._compose_sequence_node()

ext\_yaml.pyx in _yaml.CParser._compose_node()

ext\_yaml.pyx in _yaml.CParser._compose_mapping_node()

ext\_yaml.pyx in _yaml.CParser._compose_node()

ext\_yaml.pyx in _yaml.CParser._parse_next_event()

ext\_yaml.pyx in _yaml.input_handler()

~\AppData\Local\Continuum\miniconda3\envs\bluebooster_sandbox\lib\encodings\cp1250.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0] 
     24
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x83 in position 4159: character maps to <undefined>

Python 3.7.7
Windows 10
device_detector 0.10.0

on version 0.9 there is no problem.

Looks like a problem with encoding?

Regex issue while importing device_detector

When I try to import device_detector, I got the following error though I have installed regex.

Traceback (most recent call last): File "/home/ayesh/PycharmProjects/LogParcer/venv/preProcessor.py", line 4, in <module> import device_detector File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/__init__.py", line 3, in <module> from .parser import * File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/parser/__init__.py", line 1, in <module> from .client import * File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/parser/client/__init__.py", line 1, in <module> from .base import * File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/parser/client/base.py", line 7, in <module> from ..parser import Parser File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/parser/parser.py", line 9, in <module> from .extractors import ( File "/home/ayesh/PycharmProjects/LogParcer/venv/lib/python3.6/site-packages/device_detector/parser/extractors.py", line 9, in <module> APP_ID = re.compile(r'\b([a-z]{2,5}\.[\w\d\.\-]+)', re.IGNORECASE) AttributeError: module 'regex' has no attribute 'compile'

ZeroDivisionError when parsing some strings

Our system tripped on the string "]]>><". Trying to parse it resulted in the following exception:

ZeroDivisionError: division by zero
  File "device_detector/device_detector.py", line 241, in parse
    self.parse_client()
  File "device_detector/device_detector.py", line 274, in parse_client
    parser = Parser(self.user_agent, self.ua_hash, self.ua_spaceless).parse()
  File "device_detector/parser/parser.py", line 87, in parse
    self._parse()
  File "device_detector/parser/client/extractor_whole_name.py", line 64, in _parse
    if self.discard_name() or not self.is_name_length_valid():
  File "device_detector/parser/client/base.py", line 134, in discard_name
    return self.is_name_mostly_numeric()
  File "device_detector/parser/client/base.py", line 172, in is_name_mostly_numeric
    return alphabetic_chars / len(app_no_punc) < .5

Directory regexes is missing

The parsing can't work without the regexes folder :(

bots.yml does not exist
oss.yml does not exist
client/feed_readers.yml does not exist
client/mobile_apps.yml does not exist
client/mediaplayers.yml does not exist
client/pim.yml does not exist
client/browsers.yml does not exist
client/libraries.yml does not exist
device/consoles.yml does not exist
device/car_browsers.yml does not exist
device/cameras.yml does not exist
device/portable_media_player.yml does not exist
device/mobiles.yml does not exist
vendorfragments.yml does not exist

Can't install device_detector from pip

  Using cached https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz
Obtaining device-detector from git+git://github.com/AlexeyPetroff/device_detector.git@aea8e5d2033eb02389c014692e73a36e74994ab7#egg=device-detector (from -r rrrr.txt (line 2))
  Cloning git://github.com/AlexeyPetroff/device_detector.git (to revision aea8e5d2033eb02389c014692e73a36e74994ab7) to /home/al/venv/proj/project/srcdevice-detector
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/al/venv/proj/project/srcdevice-detector/setup.py", line 5, in <module>
        import device_detector
      File "/home/al/venv/proj/project/srcdevice-detector/device_detector/__init__.py", line 3, in <module>
        from .parser import *
      File "/home/al/venv/proj/project/srcdevice-detector/device_detector/parser/__init__.py", line 1, in <module>
        from .client import *
      File "/home/al/venv/proj/project/srcdevice-detector/device_detector/parser/client/__init__.py", line 1, in <module>
        from .base import *
      File "/home/al/venv/proj/project/srcdevice-detector/device_detector/parser/client/base.py", line 1, in <module>
        from ..parser import Parser
      File "/home/al/venv/proj/project/srcdevice-detector/device_detector/parser/parser.py", line 5, in <module>
        import yaml
    ModuleNotFoundError: No module named 'yaml'
    
    ----------------------------------------

From what I see the problem is that you are trying to import version from a file, where other imports are executed and they import pyYAML prematurely.

Regexp error: look-behind requires fixed-width pattern

On Windows 10, reproduced art both Python 3.6 and 3.7:

>>> from device_detector import DeviceDetector
>>> ua = 'Mozilla/5.0 (Linux; Android 4.3; C5502 Build/10.4.1.B.0.101) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'
device = DeviceDetector(ua).parse()
>>> device = DeviceDetector(ua).parse()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\pythons\python37\lib\site-packages\device_detector\device_detector.py", line 213, in parse
    self.parse_bot()
  File "c:\pythons\python37\lib\site-packages\device_detector\device_detector.py", line 272, in parse_bot
    self.bot = Bot(self.user_agent).parse()
  File "c:\pythons\python37\lib\site-packages\device_detector\parser\parser.py", line 89, in parse
    self._parse()
  File "c:\pythons\python37\lib\site-packages\device_detector\parser\parser.py", line 73, in _parse
    for ua_data in self.regex_list:
  File "c:\pythons\python37\lib\site-packages\device_detector\yaml_loader.py", line 69, in regex_list
    regex['regex'] = re.compile(BOUNDED_REGEX.format(regex['regex']), re.IGNORECASE)
  File "c:\pythons\python37\lib\re.py", line 234, in compile
    return _compile(pattern, flags)
  File "c:\pythons\python37\lib\re.py", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "c:\pythons\python37\lib\sre_compile.py", line 768, in compile
    code = _code(p, flags)
  File "c:\pythons\python37\lib\sre_compile.py", line 607, in _code
    _compile(code, p.data, flags)
  File "c:\pythons\python37\lib\sre_compile.py", line 168, in _compile
    _compile(code, p, _combine_flags(flags, add_flags, del_flags))
  File "c:\pythons\python37\lib\sre_compile.py", line 209, in _compile
    _compile(code, av, flags)
  File "c:\pythons\python37\lib\sre_compile.py", line 182, in _compile
    raise error("look-behind requires fixed-width pattern")
re.error: look-behind requires fixed-width pattern

self.all_details is None (?)

File "/app/main.py", line 184, in _ua

ua['device_type'] = parsed.device_type()

^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/device_detector/device_detector.py", line 560, in device_type

dt = self.all_details.get('device', {}).get('type', '')

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'get'

parsed.device attribute also returns None, but it looks like here its self.all_details that is causing the error. Thats not possible either cause I called .all_details, and it is definitely not None.

parsed = DeviceDetector(request.user_agent.string).parse()
ua = parsed.all_details
ua['device'] = parsed.device
ua['device_type'] = parsed.device_type()

The Package identifing galaxy gear as smartphone

hey, the useragent "Mozilla/5.0 (Linux; Tizen 2.4; SAMSUNG SM-R760) AppleWebKit/537.3 (KHTML, like Gecko) SamsungBrowser/1.1 Mobile Safari/537.3'" parsing as smartphone and not as watch.

other than that, great Package. thanks!!!

The ReadMe.md references of a device_brand_name() function

The ReadMe.md references a device_brand_name() function but I can't see it anywhere in the code and calling it fails when called

    device = DeviceDetector(user_agent).parse()
    manufacturer = device.device_brand_name()

AttributeError: 'DeviceDetector' object has no attribute 'device_brand_name'

is_bot() returns True then False for the same user agent

Hello,

I've noticed that the first time, is_bot() will return True, then False the next times for the same user agent.

With this simple script you will see :

from device_detector import DeviceDetector

user_agent = "Mozilla/5.0 (compatible; CloudFlare-AlwaysOnline/1.0; +http://www.cloudflare.com/always-online) AppleWebKit/534.34"

parsed = DeviceDetector(user_agent).parse()
print(parsed.is_bot())
parsed = DeviceDetector(user_agent).parse()
print(parsed.is_bot())

A cache problem ?

Maybe it's not only is_bot() but os_name(), os_version(), etc. that returns incorrect values too.

Thanks

is_bot() returns True then False for the same user agent

Hello,

I've noticed that the first time, is_bot() will return True, then False the next times for the same user agent.

With this simple script you will see :

from device_detector import DeviceDetector

user_agent = "Mozilla/5.0 (compatible; CloudFlare-AlwaysOnline/1.0; +http://www.cloudflare.com/always-online) AppleWebKit/534.34"

parsed = DeviceDetector(user_agent).parse()
print(parsed.is_bot()) #True
parsed = DeviceDetector(user_agent).parse()
print(parsed.is_bot()) #False

A cache problem ?

Maybe it's not only is_bot() but os_name(), os_version(), etc. that returns incorrect values too.

Thanks

Can't import

settings.py has *args before a variable name for the MAX_CACHE_SIZE. This is breaking import.

Regex trace - look-behind requires fixed-width pattern

Trying to use device-detector
from device_detector import DeviceDetector
ua = 'Mozilla/5.0 (Linux; Android 4.3; C5502 Build/10.4.1.B.0.101) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'
DeviceDetector(ua).parse() results in trace

Here is the stacktrace
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/site-packages/device_detector/device_detector.py", line 213, in parse
self.parse_bot()
File "/usr/local/lib/python3.6/site-packages/device_detector/device_detector.py", line 272, in parse_bot
self.bot = Bot(self.user_agent).parse()
File "/usr/local/lib/python3.6/site-packages/device_detector/parser/parser.py", line 89, in parse
self._parse()
File "/usr/local/lib/python3.6/site-packages/device_detector/parser/parser.py", line 73, in _parse
for ua_data in self.regex_list:
File "/usr/local/lib/python3.6/site-packages/device_detector/yaml_loader.py", line 69, in regex_list
regex['regex'] = re.compile(BOUNDED_REGEX.format(regex['regex']), re.IGNORECASE)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 566, in compile
code = _code(p, flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 551, in _code
_compile(code, p.data, flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 146, in _compile
_compile(code, p, (flags | add_flags) & ~del_flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 146, in _compile
_compile(code, p, (flags | add_flags) & ~del_flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 187, in _compile
_compile(code, av, flags)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sre_compile.py", line 160, in _compile
raise error("look-behind requires fixed-width pattern")
sre_constants.error: look-behind requires fixed-width pattern

Issue with the library?

ImportError occurs when I run device_detector.py

This is the resulting error.

Traceback (most recent call last):
File "device_detector.py", line 1, in
from .lazy_regex import RegexLazyIgnore
ImportError: attempted relative import with no known parent package

Regularly outputs "xxx does not exist" errors (0.8 from pip)

Hi, I'm seeing things like the following being printed out all the time:

device_detector/appids/secondary.yml does not exist
device_detector/appdetails/games.yml does not exist
device_detector/appdetails/messaging.yml does not exist
device_detector/appdetails/mobile_apps.yml does not exist
device_detector/appdetails/mediaplayers.yml does not exist
device_detector/appdetails/p2p.yml does not exist
device_detector/appdetails/pim.yml does not exist
device_detector/appdetails/vpnproxy.yml does not exist
device_detector/appdetails/osutility.yml does not exist
device_detector/appdetails/antivirus.yml does not exist
device_detector/appdetails/desktop_apps.yml does not exist
device_detector/appids/secondary.yml does not exist
device_detector/appids/ignored.yml does not exist
device_detector/appids/normalized.yml does not exist

unable to recognize salesforcemobilesdk

Thanks for this great package. Just found it can't recognize salesforecemobilesdk. please find the 2 example below:
SalesforceMobileSDK/7.0.0 android mobile/8.0.0 (VS996) Salesforce1/220.3(220030100) Native uid_48de40dfc42c7f9c ftr_AI.UA Cordova/7.1.2 Hybrid SalesforceMobileSDK/7.0.0 android mobile/8.0.0 (VS996) Salesforce1/220.3(220030100) Native uid_48de40dfc42c7f9c
SalesforceMobileSDK/6.1.0 iOS/12.3.1 (iPhone) Chatter/18.3(6137609) Hybrid uid_8468E465-2EC2-4B46-90B5-F83D7F0028FD ftr_GS.PN.UA Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 iPhone/12.3.1
Thanks

Unable to detect device

device_detector is unable to detect device type for following user agents.

"Kik/13.0.0.7521 (Android 7.1.1) Mozilla/5.0 (Linux; Android 7.1.1; 6060S Build/NMF26F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 Mobile Safari/537.36"
"Mozilla/5.0 (Linux; Android 5.1.1; 2014817 Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.89 Mobile Safari/537.36"
"Mozilla/5.0 (Linux; Android 5.1.1; VS985 4G Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"
"Mozilla/5.0 (Linux; Android 6.0.1; E0108 Build/MOB30R) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.158 Safari/537.36"
"Mozilla/5.0 (Linux; Android 6.0.1; FP2 Build/FP2-gms-18.04.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.101 Mobile Safari/537.36 (Ecosia [email protected])"
"Mozilla/5.0 (Linux; Android 6.0.1; S60 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.158 Mobile Safari/537.36"

Running on raspberry pi uses 100% cpu and takes 1 minute to complete

I am using this in a project of mine and started seeing cpu usage go through the roof on a raspberry pi 3b+
I need to detect this on every web request to determine which flask template to use for mobile vs desktop.
Unfortunately, it takes about 1 minute to run parse()

I have written a simple reproducing script here:

from device_detector import DeviceDetector

user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
print(f"user agent '{user_agent}'")
device = DeviceDetector(user_agent).parse()
print(f"device {device}")
print(f"is mobile? {device.is_mobile()}")

Running this

(.aprsd-venv) pi@digipi:~/aprsd $ time python dd.py
user agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
device Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
is mobile? False

real	0m52.678s
user	0m52.430s
sys	0m0.100s

System info

(.aprsd-venv) pi@digipi:~/aprsd $ python --version
Python 3.9.2
(.aprsd-venv) pi@digipi:~/aprsd $ uname -a
Linux digipi 5.15.61-v7+ #1579 SMP Fri Aug 26 11:10:59 BST 2022 armv7l GNU/Linux
(.aprsd-venv) pi@digipi:~/aprsd $ cat /etc/issue
Raspbian GNU/Linux 11 \n \l
(.aprsd-venv) pi@digipi:~/aprsd $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 76.80
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 1
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 76.80
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 2
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 76.80
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 3
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 76.80
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

Hardware	: BCM2835
Revision	: a02082
Serial		: 0000000099360b7a
Model		: Raspberry Pi 3 Model B Rev 1.2

UnicodeDecodeError

I am trying to use the dvice detactor parser in this way:

from device_detector import DeviceDetector

 ua = 'Mozilla/5.0 (Linux; Android 6.0; 4Good Light A103 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36'
device = DeviceDetector(ua).parse()

and I'm getting the following issue :

 return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8a in position 10570: character maps to <undefined>

someone have any idea what could be the issue?

thanks

Can't install with pip

Hey,
I want to try your lib but I can't install with pip :(

Collecting device_detector
  Could not find a version that satisfies the requirement device_detector (from versions: )
No matching distribution found for device_detector
 ```

Thanks

The following UAs crash the library (0.8 from pip)

If I decode any of the following UAs, I get the following error:

File "/usr/lib/python3.7/site-packages/device_detector/device_detector.py", line 237, in parse
self.parse_client()
File "/usr/lib/python3.7/site-packages/device_detector/device_detector.py", line 267, in parse_client
app_id = app_idx.extract().get('app_id', '')
File "/usr/lib/python3.7/site-packages/device_detector/parser/extractors.py", line 189, in extract
details = self.normalized_app_ids().get(app_id.lower(), {'app_id': app_id})
AttributeError: 'list' object has no attribute 'get'

Example UAs causing this:

IMAtvOS/t.3.8.0 tvOS/12.3 com.wetv.WEtviPhoneApp/2.0.94
tv.accedo.hgtv/3.3.1 (Linux;Android 5.1.1) ExoPlayerLib/2.5.4
com.hgtv.watcher/3.4.3 (Linux;Android 8.0.0) ExoPlayerLib/2.5.4
tv.accedo.foodnetwork/3.4.3 (Linux;Android 5.1.1) ExoPlayerLib/2.5.4

Example code:

from device_detector import DeviceDetector
d = DeviceDetector('IMAtvOS/t.3.8.0 tvOS/12.3 com.wetv.WEtviPhoneApp/2.0.94').parse()
device_detector/appids/secondary.yml does not exist
device_detector/appids/ignored.yml does not exist
device_detector/appids/normalized.yml does not exist
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.7/site-packages/device_detector/device_detector.py", line 237, in parse
self.parse_client()
File "/usr/lib/python3.7/site-packages/device_detector/device_detector.py", line 267, in parse_client
app_id = app_idx.extract().get('app_id', '')
File "/usr/lib/python3.7/site-packages/device_detector/parser/extractors.py", line 189, in extract
details = self.normalized_app_ids().get(app_id.lower(), {'app_id': app_id})
AttributeError: 'list' object has no attribute 'get'

Adding new yml file

First of all! This is a great library.
I would like to know how can we deal with adding new yml file for extracting custom components?

Very long parsing

Hello, and thank you for your great parser !

The only problem I'm facing is that the parsing is long, very much longer than other parsers like woothee, ua-parser or httpagentparser, BUT your results are more accurate :)

For example, with a simple script who only parse 400 lines, ua-parser made it in 1.009 seconds, and device_detector 219s.

Is there any reason ? Maybe can you look how they made it compared to you ?

Thanks a lot

Question about yml updates

Hello (it's me again),

Since your lib is a port of an original project, how do you manage if this project updates the regexes in the yml files ? Your yml files will be outdated ?
Is this somehow possible to include most up to date files ?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.