blob: d1da820b530ed5ed4237194dd1c82ebc232548e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# mypy: allow-untyped-defs
from ua_parser import user_agent_parser
def parse_user_agent(user_agent_string):
user_agent = user_agent_parser.ParseUserAgent(user_agent_string)
name = user_agent["family"]
version = "0"
if user_agent["major"] is not None:
version = user_agent["major"]
if user_agent["minor"] is not None:
version = version + "." + user_agent["minor"]
if user_agent["patch"] is not None:
version = version + "." + user_agent["patch"]
return {
"name": name,
"version": version
}
def abbreviate_browser_name(name):
short_names = {
"Chrome": "Ch",
"Chrome Mobile WebView": "Ch",
"Chromium": "Cm",
"WebKit": "Wk",
"Safari": "Sf",
"Firefox": "FF",
"IE": "IE",
"Edge": "Ed",
"Opera": "Op"
}
if name in short_names:
return short_names[name]
else:
return "Xx"
|