You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1007 B
33 lines
1007 B
def parse_user_agent(user_agent):
|
|
"""Sehr einfache, dependency-freie Grobzuordnung von Plattform/Browser aus dem
|
|
User-Agent-String - reicht für die Dashboard-Statistik, muss nicht exakt sein."""
|
|
ua = (user_agent or "").lower()
|
|
|
|
if "iphone" in ua or "ipad" in ua or "ipod" in ua:
|
|
platform = "iOS"
|
|
elif "android" in ua:
|
|
platform = "Android"
|
|
elif "windows" in ua:
|
|
platform = "Windows"
|
|
elif "macintosh" in ua or "mac os x" in ua:
|
|
platform = "macOS"
|
|
elif "linux" in ua:
|
|
platform = "Linux"
|
|
else:
|
|
platform = "Unbekannt"
|
|
|
|
if "edg/" in ua or "edga" in ua or "edgios" in ua:
|
|
browser = "Edge"
|
|
elif "opr/" in ua or "opera" in ua:
|
|
browser = "Opera"
|
|
elif "firefox" in ua or "fxios" in ua:
|
|
browser = "Firefox"
|
|
elif "crios" in ua or "chrome" in ua:
|
|
browser = "Chrome"
|
|
elif "safari" in ua:
|
|
browser = "Safari"
|
|
else:
|
|
browser = "Unbekannt"
|
|
|
|
return platform, browser
|