From 2f2f1c61cdaab5d365e4537198aac0f7b6151aa5 Mon Sep 17 00:00:00 2001 From: Ale Sanchez Date: Fri, 13 Aug 2021 10:51:12 +0200 Subject: [PATCH] fix: Several fixes --- .editorconfig | 13 +++++++++++++ covid_data/__init__.py | 2 +- covid_data/{app.py => covid_data} | 6 ++++-- covid_data/logger.py | 12 ++++++------ covid_data/scrappers/france.py | 10 ++++------ covid_data/scrappers/spain.py | 10 ++++------ setup.py | 3 ++- 7 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 .editorconfig rename covid_data/{app.py => covid_data} (89%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..73da82d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root=true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.py] +charset = utf-8 +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab diff --git a/covid_data/__init__.py b/covid_data/__init__.py index 4c8c396..469d8da 100644 --- a/covid_data/__init__.py +++ b/covid_data/__init__.py @@ -1,4 +1,4 @@ from covid_data import db as db # noqa: F401 from covid_data import types as types # noqa: F401 +from covid_data.db import queries as queries # noqa: F401 from covid_data.utils import places as places_utils # noqa: F401 -from db import queries as queries # noqa: F401 diff --git a/covid_data/app.py b/covid_data/covid_data similarity index 89% rename from covid_data/app.py rename to covid_data/covid_data index 9120770..a79edd5 100644 --- a/covid_data/app.py +++ b/covid_data/covid_data @@ -1,13 +1,15 @@ +#!/usr/bin/env python import os from importlib import import_module import click -from covid_data.logger import init_logger from dotenv import load_dotenv +from covid_data.logger import init_logger + load_dotenv() -init_logger(os.path.join(os.path.dirname(__file__), "../logs/covid_data.log")) +init_logger() @click.group() diff --git a/covid_data/logger.py b/covid_data/logger.py index faed94b..bc2cda4 100644 --- a/covid_data/logger.py +++ b/covid_data/logger.py @@ -3,21 +3,21 @@ import sys -def init_logger(logfile: str, level: int = logging.DEBUG): +def init_logger(level: int = logging.DEBUG): """Initialize the root logger and standard log handlers.""" log_formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) - root_logger = logging.getLogger() + root_logger = logging.getLogger("covid_data") root_logger.setLevel(level) - file_handler = logging.FileHandler(logfile) - file_handler.setFormatter(log_formatter) - root_logger.addHandler(file_handler) + console_handler = logging.StreamHandler() + console_handler.setFormatter(log_formatter) + root_logger.addHandler(console_handler) sys.excepthook = log_uncaught_exception def log_uncaught_exception(type, value, traceback): - root_logger = logging.getLogger() + root_logger = logging.getLogger("covid_data") root_logger.exception(f"Uncaught exception: {value}") diff --git a/covid_data/scrappers/france.py b/covid_data/scrappers/france.py index 73adbb2..663bd71 100644 --- a/covid_data/scrappers/france.py +++ b/covid_data/scrappers/france.py @@ -6,14 +6,15 @@ import click import requests from click.exceptions import ClickException +from psycopg2._psycopg import connection # pylint: disable=no-name-in-module + from covid_data.db import close_db, get_db from covid_data.db.queries import OnConflictStrategy, create_case from covid_data.logger import init_logger from covid_data.types import CaseType, PlaceType from covid_data.utils.places import create_country, create_province -from psycopg2._psycopg import connection # pylint: disable=no-name-in-module -logger = logging.getLogger("covid-data") +logger = logging.getLogger("covid_data") START_DATE = datetime.datetime(2020, 3, 2) @@ -122,10 +123,7 @@ def scrap(engine: connection, start_date: datetime.datetime = START_DATE) -> Non from dotenv import load_dotenv load_dotenv() - init_logger( - os.path.join(os.path.dirname(__file__), "../../logs/covid_data.log"), - logging.INFO, - ) + init_logger(logging.INFO) engine = get_db() try: diff --git a/covid_data/scrappers/spain.py b/covid_data/scrappers/spain.py index 6cf6f25..5406186 100644 --- a/covid_data/scrappers/spain.py +++ b/covid_data/scrappers/spain.py @@ -7,14 +7,15 @@ import requests from bs4 import BeautifulSoup from bs4.element import Tag +from psycopg2._psycopg import connection # pylint: disable=no-name-in-module + from covid_data.db import close_db, get_db from covid_data.db.queries import create_case from covid_data.logger import init_logger from covid_data.types import CaseType, OnConflictStrategy from covid_data.utils.places import create_country, create_province -from psycopg2._psycopg import connection # pylint: disable=no-name-in-module -logger = logging.getLogger("covid-data") +logger = logging.getLogger("covid_data") START_DATE = datetime(2020, 3, 2) @@ -103,10 +104,7 @@ def scrap(engine: connection, start_date: datetime = START_DATE) -> None: load_dotenv() - init_logger( - os.path.join(os.path.dirname(__file__), "../../logs/covid_data.log"), - logging.INFO, - ) + init_logger(logging.INFO) engine = get_db() try: diff --git a/setup.py b/setup.py index 229f98f..caddb73 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ with open("README.md", "r", encoding="utf-8") as fp: long_description = fp.read() -__version__ = "0.1.7" +__version__ = "0.1.13" download_url = "https://github.com/alesanmed-educational-projects/covid-data/archive/refs/tags/{}.tar.gz".format( __version__ @@ -11,6 +11,7 @@ setup( name="covid_data", + scripts=["covid_data/covid_data"], packages=find_packages(), version=__version__, license="The Unlicense",