Compare commits

...
7 Commits
Author SHA1 Message Date
brb 3c1d93726e updated workflow
Python application / build (push) Successful in 31s
2023-07-11 10:04:06 +02:00
brb 4ccb357f7c fixed linting 2023-07-11 10:03:49 +02:00
brb cfbf544110 fixed linting 2023-07-11 10:00:44 +02:00
brb 5e5fb31767 removed unused imports 2023-07-11 09:59:34 +02:00
brb d4e5728015 added logging 2023-07-11 09:59:24 +02:00
brb a9818001d5 corrected linting 2023-07-11 09:58:09 +02:00
brb b51460b696 added logging 2023-07-11 09:57:38 +02:00
5 changed files with 23 additions and 16 deletions
+1 -4
View File
@@ -13,14 +13,11 @@ jobs:
with: with:
python-version: "3.10" python-version: "3.10"
architecture: "x64" architecture: "x64"
- name: Install Dependencies - name: Install Packages
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flake8 pytest pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8 - name: Lint with flake8
run: | run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ./code flake8 ./code
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 ./code --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
+2 -1
View File
@@ -1,6 +1,6 @@
from speedtest import Speedtest from speedtest import Speedtest
from dotenv import load_dotenv from dotenv import load_dotenv
from typing import List import logging
def measure(): def measure():
@@ -13,6 +13,7 @@ def measure():
s.download(threads=None) s.download(threads=None)
s.upload(threads=None) s.upload(threads=None)
s.results.share() s.results.share()
logging.debug('finished')
return s.results.dict() return s.results.dict()
+2
View File
@@ -3,6 +3,7 @@ from dotenv import load_dotenv
import logging import logging
import os import os
def connect( def connect(
ip_addr: str | None = None, ip_addr: str | None = None,
db_name: str | None = None, db_name: str | None = None,
@@ -22,6 +23,7 @@ def connect(
client = MongoClient(ip_addr) client = MongoClient(ip_addr)
db = client[db_name] db = client[db_name]
collection = db[collection_name] collection = db[collection_name]
logging.debug('finished')
return collection return collection
+11 -4
View File
@@ -6,7 +6,8 @@ import os
def initialise_app(): def initialise_app():
""" """
Convienience function that ensures eveything is ready before running main loop. Convienience function that ensures eveything is ready
before running the main loop.
""" """
# load environment variables from file # load environment variables from file
load_dotenv() load_dotenv()
@@ -16,7 +17,10 @@ def initialise_app():
logger_level = os.getenv('LOGGER_LEVEL', default=None) logger_level = os.getenv('LOGGER_LEVEL', default=None)
if logger_level is None: if logger_level is None:
logger_level = 'info' logger_level = 'info'
logging.info(f'environment variable LOGGER_LEVEL not set. Using default (info)') logging.info(
'environment variable LOGGER_LEVEL not set. '
'Using default (info)'
)
level = getattr(logging, logger_level.upper()) level = getattr(logging, logger_level.upper())
logging.basicConfig(format=fmt, datefmt=datefmt, level=level) logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
# setup logging to discord # setup logging to discord
@@ -45,8 +49,11 @@ def initialise_app():
'TRIGGER_INTERVAL_SECONDS': 60 'TRIGGER_INTERVAL_SECONDS': 60
} }
for k, v in default_dict.items(): for k, v in default_dict.items():
if not k in os.environ: if k not in os.environ:
logging.info(f'environment variable {k} not set. Using default ({v}).') logging.info(
f'environment variable {k} not set. '
f'Using default ({v}).'
)
os.environ[k] = str(v) os.environ[k] = str(v)
+2 -2
View File
@@ -1,11 +1,11 @@
import time import time
import logging import logging
import time
import os import os
from initialise_app import initialise_app from initialise_app import initialise_app
from bandwidth import measure as measure_bandwidth from bandwidth import measure as measure_bandwidth
from database import connect from database import connect
def event(): def event():
logging.info('started event') logging.info('started event')
# get env vars # get env vars
@@ -35,6 +35,7 @@ def event():
time.sleep(1) time.sleep(1)
logging.info('finished event') logging.info('finished event')
if __name__ == '__main__': if __name__ == '__main__':
initialise_app() initialise_app()
trigger_time = time.time() trigger_time = time.time()
@@ -48,4 +49,3 @@ if __name__ == '__main__':
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
time.sleep(1) time.sleep(1)