device detection

This commit is contained in:
Aitzol 2023-04-04 13:25:10 +02:00
parent cf169efe5f
commit 93f79cb4f0
2 changed files with 15 additions and 1 deletions

13
app.py
View File

@ -34,11 +34,12 @@ from libs import flist, slist
from libs.localization import *
from libs.helper import *
import random
from user_agents import parse
BASE_DIR = path.dirname(__file__)
LOG = logging.getLogger(__name__)
LOG_FORMAT = '%(asctime)s %(levelname)s: %(message)s'
VERSION = '0.0.1'
VERSION = '0.0.2'
@get('/')
def get_index():
@ -50,6 +51,7 @@ def get_index():
@get('/user')
def get_index():
try:
print(newSession().get())
return user_tpl(data=newSession().get(), str=i18n.str)
except Exception as e:
return index_tpl(str=i18n.str)
@ -833,6 +835,14 @@ def newSession():
global i18n
i18n = LocalizeTo(self.lang, CONF)
self.device = self.get_dev()
def get_dev(self):
ua_string = bottle.request.environ.get('HTTP_USER_AGENT')
user_agent = parse(ua_string)
return str(user_agent)
def get_lang(self):
if 'HTTP_ACCEPT_LANGUAGE' in bottle.request.environ:
lang = bottle.request.get('HTTP_ACCEPT_LANGUAGE')
@ -860,6 +870,7 @@ def newSession():
self.data['surname'] = self.surname
self.data['username'] = self.username
self.data['mail'] = self.mail
self.data['device'] = self.device
def close(self):
self.data.pop('username')

View File

@ -2,3 +2,6 @@ bottle>=0.12.19
bottle-beaker>=0.1.3
ldap3>=2.9.1
uwsgi>=2.0.21
pyyaml>=6.0
ua-parser>=0.16.1
user-agents>=2.2.0