Added more logging

This commit is contained in:
Pünkösd Marcell 2021-04-14 21:16:20 +02:00
parent ffa20ea1fc
commit e4a28d7446

View File

@ -1,14 +1,21 @@
from program_schema import ProgramSchema, SUPPORTED_PROGRAM_STRUCTURE_VERSION
import requests
import logging
def load_program(url: str) -> dict:
logger = logging.getLogger('loader')
headers = {
'Accept': 'application/json'
'Accept': 'application/json',
}
logger.debug(f"Performing HTTP request: (url: {url}, headers: {headers})")
r = requests.get(url, headers=headers)
r.raise_for_status()
logger.debug(f"HTTP Status: {r.status_code}; Validating downloaded info...")
program_schema = ProgramSchema(many=False)
program = program_schema.load(r.json()) # Might raise marshmallow exceptions
return program_schema.load(r.json()) # Might raise marshmallow exceptions
logger.info(f"Loaded {program.get('name')} (Created at: {program.get('created_at')}) from {url}")
return program