Skip to content

Commit

Permalink
chg: Bump deps, update ua-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Dec 2, 2024
1 parent deadc95 commit 5e65877
Show file tree
Hide file tree
Showing 3 changed files with 571 additions and 463 deletions.
19 changes: 10 additions & 9 deletions lookyloo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import configparser
import dataclasses
import gzip
import hashlib
import json
Expand Down Expand Up @@ -30,7 +31,7 @@
from playwrightcapture import get_devices
from publicsuffixlist import PublicSuffixList # type: ignore[import-untyped]
from pytaxonomies import Taxonomies # type: ignore[attr-defined]
from ua_parser import user_agent_parser # type: ignore[import-untyped]
import ua_parser
from werkzeug.user_agent import UserAgent
from werkzeug.utils import cached_property

Expand Down Expand Up @@ -374,30 +375,30 @@ class ParsedUserAgent(UserAgent):
# from https://python.tutorialink.com/how-do-i-get-the-user-agent-with-flask/

@cached_property
def _details(self) -> dict[str, Any]:
return user_agent_parser.Parse(self.string)
def _details(self) -> ua_parser.DefaultedResult:
return ua_parser.parse(self.string).with_defaults()

@property
def platform(self) -> str | None: # type: ignore[override]
return self._details['os'].get('family')
return self._details.os.family

@property
def platform_version(self) -> str | None:
return self._aggregate_version(self._details['os'])
return self._aggregate_version(self._details.os)

@property
def browser(self) -> str | None: # type: ignore[override]
return self._details['user_agent'].get('family')
return self._details.user_agent.family

@property
def version(self) -> str | None: # type: ignore[override]
return self._aggregate_version(self._details['user_agent'])
return self._aggregate_version(self._details.user_agent)

def _aggregate_version(self, details: dict[str, str]) -> str | None:
def _aggregate_version(self, details: ua_parser.OS | ua_parser.UserAgent) -> str | None:
return '.'.join(
part
for key in ('major', 'minor', 'patch', 'patch_minor')
if (part := details.get(key)) is not None
if (part := dataclasses.asdict(details).get(key)) is not None
)

def __str__(self) -> str:
Expand Down
Loading

0 comments on commit 5e65877

Please sign in to comment.