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
+2 -5
View File
@@ -13,14 +13,11 @@ jobs:
with:
python-version: "3.10"
architecture: "x64"
- name: Install Dependencies
- name: Install Packages
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
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
flake8 ./code
+2 -1
View File
@@ -1,6 +1,6 @@
from speedtest import Speedtest
from dotenv import load_dotenv
from typing import List
import logging
def measure():
@@ -13,6 +13,7 @@ def measure():
s.download(threads=None)
s.upload(threads=None)
s.results.share()
logging.debug('finished')
return s.results.dict()
+3 -1
View File
@@ -3,6 +3,7 @@ from dotenv import load_dotenv
import logging
import os
def connect(
ip_addr: str | None = None,
db_name: str | None = None,
@@ -22,10 +23,11 @@ def connect(
client = MongoClient(ip_addr)
db = client[db_name]
collection = db[collection_name]
logging.debug('finished')
return collection
if __name__ == '__main__':
load_dotenv()
collection = connect()
print(collection)
print(collection)
+14 -7
View File
@@ -6,7 +6,8 @@ import os
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_dotenv()
@@ -16,7 +17,10 @@ def initialise_app():
logger_level = os.getenv('LOGGER_LEVEL', default=None)
if logger_level is None:
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())
logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
# setup logging to discord
@@ -24,8 +28,8 @@ def initialise_app():
assert discord_url is not None
logger = logging.getLogger()
discord_handler = DiscordHandler(
service_name = 'bandwidth_probing',
webhook_url = discord_url,
service_name='bandwidth_probing',
webhook_url=discord_url,
)
discord_handler.setFormatter(logging.Formatter('%(message)s'))
discord_handler.setLevel(logging.WARNING)
@@ -45,11 +49,14 @@ def initialise_app():
'TRIGGER_INTERVAL_SECONDS': 60
}
for k, v in default_dict.items():
if not k in os.environ:
logging.info(f'environment variable {k} not set. Using default ({v}).')
if k not in os.environ:
logging.info(
f'environment variable {k} not set. '
f'Using default ({v}).'
)
os.environ[k] = str(v)
if __name__ == '__main__':
initialise_app()
logging.warning('test message')
logging.warning('test message')
+2 -2
View File
@@ -1,11 +1,11 @@
import time
import logging
import time
import os
from initialise_app import initialise_app
from bandwidth import measure as measure_bandwidth
from database import connect
def event():
logging.info('started event')
# get env vars
@@ -35,6 +35,7 @@ def event():
time.sleep(1)
logging.info('finished event')
if __name__ == '__main__':
initialise_app()
trigger_time = time.time()
@@ -48,4 +49,3 @@ if __name__ == '__main__':
except Exception as e:
logging.error(e)
time.sleep(1)