mirror of
https://github.com/craigerl/aprsd.git
synced 2025-04-05 02:58:31 -04:00
change from device-detector to user-agents
the device detector was taking 1 minute on a raspi to parse out the user-agent string from the browser. user-agents takes 2 seconds, which still isn't great, but 'doable' for the webchat interface.
This commit is contained in:
parent
1e65af2dea
commit
f2b1ad35f9
@ -9,13 +9,13 @@ import time
|
||||
|
||||
from aprslib import util as aprslib_util
|
||||
import click
|
||||
from device_detector import DeviceDetector
|
||||
import flask
|
||||
from flask import request
|
||||
from flask.logging import default_handler
|
||||
import flask_classful
|
||||
from flask_httpauth import HTTPBasicAuth
|
||||
from flask_socketio import Namespace, SocketIO
|
||||
from user_agents import parse as ua_parse
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
import wrapt
|
||||
|
||||
@ -237,10 +237,16 @@ class WebChatFlask(flask_classful.FlaskView):
|
||||
)
|
||||
)
|
||||
elif transport == client.TRANSPORT_SERIALKISS:
|
||||
# for pep8 violation
|
||||
kiss_default = aprsd_config.DEFAULT_DATE_FORMAT["kiss"]
|
||||
default_baudrate = kiss_default["serial"]["baudrate"]
|
||||
aprs_connection = (
|
||||
"SerialKISS://{}@{} baud".format(
|
||||
self.config["kiss"]["serial"]["device"],
|
||||
self.config["kiss"]["serial"]["baudrate"],
|
||||
self.config["kiss"]["serial"].get(
|
||||
"baudrate",
|
||||
default_baudrate,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@ -248,13 +254,13 @@ class WebChatFlask(flask_classful.FlaskView):
|
||||
|
||||
@auth.login_required
|
||||
def index(self):
|
||||
user_agent = request.headers.get("User-Agent")
|
||||
device = DeviceDetector(user_agent).parse()
|
||||
LOG.debug(f"Device type {device.device_type()}")
|
||||
LOG.debug(f"Is mobile? {device.is_mobile()}")
|
||||
ua_str = request.headers.get("User-Agent")
|
||||
# this takes about 2 seconds :(
|
||||
user_agent = ua_parse(ua_str)
|
||||
LOG.debug(f"Is mobile? {user_agent.is_mobile}")
|
||||
stats = self._stats()
|
||||
|
||||
if device.is_mobile():
|
||||
if user_agent.is_mobile:
|
||||
html_template = "mobile.html"
|
||||
else:
|
||||
html_template = "index.html"
|
||||
@ -549,6 +555,7 @@ def webchat(ctx, flush, port):
|
||||
LOG.info("Start socketio.run()")
|
||||
socketio.run(
|
||||
app,
|
||||
ssl_context="adhoc",
|
||||
host=config["aprsd"]["web"]["host"],
|
||||
port=port,
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with python 3.9
|
||||
# To update, run:
|
||||
# This file is autogenerated by pip-compile with Python 3.9
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile --annotation-style=line --resolver=backtracking dev-requirements.in
|
||||
#
|
||||
@ -11,10 +11,13 @@ autoflake==1.5.3 # via gray
|
||||
babel==2.11.0 # via sphinx
|
||||
black==22.10.0 # via gray
|
||||
build==0.9.0 # via pip-tools
|
||||
cachetools==5.2.0 # via tox
|
||||
certifi==2022.9.24 # via requests
|
||||
cfgv==3.3.1 # via pre-commit
|
||||
chardet==5.1.0 # via tox
|
||||
charset-normalizer==2.1.1 # via requests
|
||||
click==8.1.3 # via black, pip-tools
|
||||
colorama==0.4.6 # via tox
|
||||
commonmark==0.9.1 # via rich
|
||||
configargparse==1.5.3 # via gray
|
||||
coverage[toml]==6.5.0 # via pytest-cov
|
||||
@ -29,7 +32,7 @@ identify==2.5.9 # via pre-commit
|
||||
idna==3.4 # via requests
|
||||
imagesize==1.4.1 # via sphinx
|
||||
importlib-metadata==5.1.0 # via sphinx
|
||||
importlib-resources==5.10.0 # via fixit
|
||||
importlib-resources==5.10.1 # via fixit
|
||||
iniconfig==1.1.1 # via pytest
|
||||
isort==5.10.1 # via -r dev-requirements.in, gray
|
||||
jinja2==3.1.2 # via sphinx
|
||||
@ -40,28 +43,27 @@ mccabe==0.7.0 # via flake8
|
||||
mypy==0.991 # via -r dev-requirements.in
|
||||
mypy-extensions==0.4.3 # via black, mypy, typing-inspect
|
||||
nodeenv==1.7.0 # via pre-commit
|
||||
packaging==21.3 # via build, pytest, sphinx, tox
|
||||
packaging==21.3 # via build, pyproject-api, pytest, sphinx, tox
|
||||
pathspec==0.10.2 # via black
|
||||
pep517==0.13.0 # via build
|
||||
pep8-naming==0.13.2 # via -r dev-requirements.in
|
||||
pip-tools==6.11.0 # via -r dev-requirements.in
|
||||
platformdirs==2.5.4 # via black, virtualenv
|
||||
platformdirs==2.6.0 # via black, tox, virtualenv
|
||||
pluggy==1.0.0 # via pytest, tox
|
||||
pre-commit==2.20.0 # via -r dev-requirements.in
|
||||
py==1.11.0 # via tox
|
||||
pycodestyle==2.10.0 # via flake8
|
||||
pyflakes==3.0.1 # via autoflake, flake8
|
||||
pygments==2.13.0 # via rich, sphinx
|
||||
pyparsing==3.0.9 # via packaging
|
||||
pyproject-api==1.2.1 # via tox
|
||||
pyrsistent==0.19.2 # via jsonschema
|
||||
pytest==7.2.0 # via -r dev-requirements.in, pytest-cov
|
||||
pytest-cov==4.0.0 # via -r dev-requirements.in
|
||||
pytz==2022.6 # via babel
|
||||
pyupgrade==3.3.0 # via gray
|
||||
pyupgrade==3.3.1 # via gray
|
||||
pyyaml==6.0 # via fixit, libcst, pre-commit
|
||||
requests==2.28.1 # via sphinx
|
||||
rich==12.6.0 # via gray
|
||||
six==1.16.0 # via tox
|
||||
snowballstemmer==2.2.0 # via sphinx
|
||||
sphinx==5.3.0 # via -r dev-requirements.in
|
||||
sphinxcontrib-applehelp==1.0.2 # via sphinx
|
||||
@ -72,14 +74,14 @@ sphinxcontrib-qthelp==1.0.3 # via sphinx
|
||||
sphinxcontrib-serializinghtml==1.1.5 # via sphinx
|
||||
tokenize-rt==5.0.0 # via add-trailing-comma, pyupgrade
|
||||
toml==0.10.2 # via autoflake, pre-commit
|
||||
tomli==2.0.1 # via black, build, coverage, mypy, pep517, pytest, tox
|
||||
tox==3.27.1 # via -r dev-requirements.in
|
||||
tomli==2.0.1 # via black, build, coverage, mypy, pep517, pyproject-api, pytest, tox
|
||||
tox==4.0.0 # via -r dev-requirements.in
|
||||
typing-extensions==4.4.0 # via black, libcst, mypy, typing-inspect
|
||||
typing-inspect==0.8.0 # via libcst
|
||||
unify==0.5 # via gray
|
||||
untokenize==0.1.1 # via unify
|
||||
urllib3==1.26.13 # via requests
|
||||
virtualenv==20.17.0 # via pre-commit, tox
|
||||
virtualenv==20.17.1 # via pre-commit, tox
|
||||
wheel==0.38.4 # via pip-tools
|
||||
zipp==3.11.0 # via importlib-metadata, importlib-resources
|
||||
|
||||
|
@ -25,4 +25,4 @@ wrapt
|
||||
kiss3
|
||||
attrs==22.1.0
|
||||
# for mobile checking
|
||||
device-detector
|
||||
user-agents
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with python 3.9
|
||||
# To update, run:
|
||||
# This file is autogenerated by pip-compile with Python 3.9
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile --annotation-style=line --resolver=backtracking requirements.in
|
||||
#
|
||||
@ -15,7 +15,6 @@ charset-normalizer==2.1.1 # via requests
|
||||
click==8.1.3 # via -r requirements.in, click-completion, flask
|
||||
click-completion==0.5.2 # via -r requirements.in
|
||||
commonmark==0.9.1 # via rich
|
||||
device-detector==5.0.1 # via -r requirements.in
|
||||
dnspython==2.2.1 # via eventlet
|
||||
eventlet==0.33.2 # via -r requirements.in
|
||||
flask==2.1.2 # via -r requirements.in, flask-classful, flask-httpauth, flask-socketio
|
||||
@ -38,8 +37,7 @@ pyserial-asyncio==0.6 # via kiss3
|
||||
python-engineio==4.3.4 # via python-socketio
|
||||
python-socketio==5.7.2 # via flask-socketio
|
||||
pytz==2022.6 # via -r requirements.in
|
||||
pyyaml==6.0 # via -r requirements.in, device-detector
|
||||
regex==2022.10.31 # via device-detector
|
||||
pyyaml==6.0 # via -r requirements.in
|
||||
requests==2.28.1 # via -r requirements.in, update-checker
|
||||
rich==12.6.0 # via -r requirements.in
|
||||
shellingham==1.5.0 # via click-completion
|
||||
@ -47,8 +45,10 @@ six==1.16.0 # via -r requirements.in, click-completion, eventlet,
|
||||
soupsieve==2.3.2.post1 # via beautifulsoup4
|
||||
tabulate==0.9.0 # via -r requirements.in
|
||||
thesmuggler==1.0.1 # via -r requirements.in
|
||||
ua-parser==0.16.1 # via user-agents
|
||||
update-checker==0.18.0 # via -r requirements.in
|
||||
urllib3==1.26.13 # via requests
|
||||
user-agents==2.2.0 # via -r requirements.in
|
||||
werkzeug==2.1.2 # via -r requirements.in, flask
|
||||
wrapt==1.14.1 # via -r requirements.in
|
||||
zipp==3.11.0 # via importlib-metadata
|
||||
|
Loading…
Reference in New Issue
Block a user