# Phonofile Mechanicals file generation

This repo houses the code needed to run the monthly phonofile mechanicals report.

First, this repo uses poetry (pipenv can also be used) to manage dependices/virtual environment

To install poetry if not installed run:
`curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - `

To install: `poetry install`

To active the environment (if not already activated): `poetry shell`

Next, rename .env.shadow to .env and fill in Snowflake username and password with your creds.

To load env variables: `source .env` **Note: If you get a Snowflake connection error you likely did not load the env variables**

`cd phonofile mechanicals` in order to move to the correct directory

**Note: redessent_mechanicals/ can be ignored as we don't support this anymore, but the code is there**

Look at the sql in *ingest_profitcenters.sql*....this contains the code to create a profit center mapping table.

Take the file Michael sends, and create a new csv containing the column: labelid, customerid, profitcenter and upload to S3 as `s3://dev-dataanalyticsdept/misc/phonofile_profit_center_mapping.csv`

Next, copy the sql into the snowflake console and run to create the mapping table.

Lastly, run `python generate_phonofile_mechanicals.py` to generate the file which appears in the same directory as `phonofile_upload.csv`. **Note: You will have to approve 2FA when this runs**

As a final step, do a find + replace in the csv output to change the posting date to whatever date is asked for in the email!

Done!
