Skip to main content

An extension that registers all pharmacies in Argentina.

Project description

PymaciesArg

Build status codecov Documentation Status docstr-cov GitHub license Forks star issues GitHub contributors black

PymaciesArg is an extension that registers all pharmacies in Argentina.

Features

Requirements

Python 3.8+

Dependecies for this project.

intallation

You can install via pip:

    $> pip install PymaciesArg

Example

Register the extension:

import os
import pathlib

import click

from pymacies_arg import (
    DepartmentsLoader,
    LocationsLoader,
    PharmaciesLoader,
    PymaciesArg,
    TABLE_NAMES,
)

from sqlalchemy import create_engine

# this path is pointing to project/
PATH = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = "sqlite:///" + PATH + "/db_data.db"

engine = create_engine(SQLALCHEMY_DATABASE_URI)


# this path is pointing to project/sample_app_sqlite
CURRENT_PATH = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))

query1 = """CREATE TABLE IF NOT EXISTS pharmacies (
    "id"  INTEGER PRIMARY KEY,
    "name" VARCHAR(255) NOT NULL,
    "id_location"  INTEGER NOT NULL,
    "id_department"  INTEGER NOT NULL,
    "postal_code"  INTEGER NOT NULL,
    "adress" VARCHAR(255) NOT NULL);"""

query2 = """CREATE TABLE IF NOT EXISTS department (
    "id_department"  INTEGER NOT NULL PRIMARY KEY,
    "department" VARCHAR(255) NOT NULL,
    FOREIGN KEY (id_department) REFERENCES pharmacies(id_department));"""

query3 = """CREATE TABLE IF NOT EXISTS "locations"(
    "id_location"  INTEGER PRIMARY KEY,
    "location" VARCHAR(255) NOT NULL,
    FOREIGN KEY (id_location) REFERENCES pharmacies(id_location));"""


def create_table():
    with engine.connect() as conn:
        for tname in TABLE_NAMES[0:3]:
            print(f"create table {tname}")
            for q in [query1, query2, query3]:
                conn.execute(f"DROP TABLE IF EXISTS {tname};")
                conn.execute(q)


# : configure the command for run pipeline.
@click.command()
@click.option("--date", help="run date in format yyyy-mm-dd")
@click.argument("province")
def run_pipeline(date, province) -> None:

    pymacies = PymaciesArg(date, CURRENT_PATH)
    # Extract
    print("Extracting")
    file_paths = pymacies.extract_raws()

    # Transform
    print("Tansform")
    paths = pymacies.trasform_raws(file_paths, province)

    # Load
    print("Loading")
    PharmaciesLoader(engine).load_table(paths[0])
    LocationsLoader(engine).load_table(paths[1])
    DepartmentsLoader(engine).load_table(paths[2])

    # Done
    print("Done!")


if __name__ == "__main__":
    create_table()
    run_pipeline()
  1. run the following command line:

    $> python -m scripts --date 2022-10-16 "BUENOS AIRES"
    

Recommended running instructions for dev:

  1. Create a virtual environment:

    $> python3 -m venv venv
    
  2. Activate the newly created environment:

    On macOS and Linux:

    $> source venv/bin/activate
    

    On Windows

    c:\> .\env\Scripts\activate
    
  3. Install dependencies:

    $> (venv) python -m pip install -r requirements/dev.txt
    
  4. Start the sample app on server locally:

    $> (venv) pip install -e .
    
  5. Start the sample app on server locally:

    $> (venv) python application/pipeline.py
    10/16/2022 04:58:34 AM - pymacies_arg - INFO - Extracting
    10/16/2022 04:58:35 AM - pymacies_arg - INFO - Tansform
    10/16/2022 04:58:38 AM - pymacies_arg - INFO - Loading
    10/16/2022 04:58:40 AM - pymacies_arg - INFO - Done!
    

Links

Authors

  • Ferreira, Juan David

Please submit bug reports, suggestions for improvements and patches via the (E-mail: juandavid9a0@gmail.com).

Contributors

Credits goes to these peoples:

Official repository and Issues

License

PymaciesArg is free software you can redistribute it and/or modify it under the terms of the MIT License. For more information, you can see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PymaciesArg-0.0.1.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distribution

PymaciesArg-0.0.1-py3-none-any.whl (11.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page