Skip to content

Commit

Permalink
fix: move logging config to collect_data script
Browse files Browse the repository at this point in the history
  • Loading branch information
mrw298 committed Dec 6, 2023
1 parent f95603c commit c7df4c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 6 additions & 0 deletions uk_bin_collection/uk_bin_collection/collect_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import importlib
import os
import sys
import logging
from uk_bin_collection.uk_bin_collection.get_bin_data import setup_logging, LOGGING_CONFIG

_LOGGER = logging.getLogger(__name__)

# We use this method to dynamically import the council processor
SRC_PATH = os.path.join("councils")
Expand Down Expand Up @@ -91,6 +95,8 @@ def run(self):
if __name__ == "__main__":
import sys

_LOGGER = setup_logging(LOGGING_CONFIG, None)

app = UKBinCollectionApp()
app.set_args(sys.argv[1:])
data = app.run()
Expand Down
14 changes: 6 additions & 8 deletions uk_bin_collection/uk_bin_collection/get_bin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from uk_bin_collection.uk_bin_collection.common import update_input_json

_LOGGER = logging.getLogger(__name__)

LOGGING_CONFIG = dict(
version=1,
formatters={"f": {"format": "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"}},
Expand All @@ -30,10 +32,6 @@ def setup_logging(logging_config, logger_name):
except Exception as exp:
raise exp


LOGGER = setup_logging(LOGGING_CONFIG, None)


# import the wonderful Beautiful Soup and the URL grabber


Expand Down Expand Up @@ -99,16 +97,16 @@ def get_data(cls, url) -> str:
full_page = requests.get(url, headers, verify=False)
return full_page
except requests.exceptions.HTTPError as errh:
LOGGER.error(f"Http Error: {errh}")
_LOGGER.error(f"Http Error: {errh}")
raise
except requests.exceptions.ConnectionError as errc:
LOGGER.error(f"Error Connecting: {errc}")
_LOGGER.error(f"Error Connecting: {errc}")
raise
except requests.exceptions.Timeout as errt:
LOGGER.error(f"Timeout Error: {errt}")
_LOGGER.error(f"Timeout Error: {errt}")
raise
except requests.exceptions.RequestException as err:
LOGGER.error(f"Oops: Something Else {err}")
_LOGGER.error(f"Oops: Something Else {err}")
raise

@abstractmethod
Expand Down

0 comments on commit c7df4c5

Please sign in to comment.