Skip to content

Commit

Permalink
fix: Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanmed committed Aug 13, 2021
1 parent 8a4b6a8 commit 2f2f1c6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion covid_data/__init__.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions covid_data/app.py → covid_data/covid_data
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
12 changes: 6 additions & 6 deletions covid_data/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
10 changes: 4 additions & 6 deletions covid_data/scrappers/france.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions covid_data/scrappers/spain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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__
)

setup(
name="covid_data",
scripts=["covid_data/covid_data"],
packages=find_packages(),
version=__version__,
license="The Unlicense",
Expand Down

0 comments on commit 2f2f1c6

Please sign in to comment.