This project is to automate the process of creating the weekly Qxf2 newsletter. We take the URLs posted on the Skype channel as input and create a MailChimp campaign.
-
Clone the repository
-
Setup and activate a virtual environment:
virtualenv env
source env\Scripts\activate -
Install the dependencies
python -m pip install -r requirements.txt -
Install MySQL and setup a database called
newsletter_automation -
Setup the following environment variables in your environment
export FLASK_APP=run.py
export CLIENT_ID="Your Google Client ID"
export CLIENT_SECRET="Your Google Secret"
export SERVER_PREFIX="Your Server Prefix"
export SUBSCRIBER_LIST_ID="Your Mailchimp subscriber list"
export MAILCHIMP_API_KEY="Your Mailchimp API key"
export MYSQL_USERNAME="Your MYSQL username"
export MYSQL_PASSWORD="Your MYSQL password"
export API_KEY="API KEY OF YOUR CHOICE"
NOTE: For Qxf2 employees, please ask a colleague to share the right vault with you for these values. -
Run
cd newsletter_automation
flask db stamp head
flask db migrate -
Manually insert data into article_category using below query:
insert into article_category (category_name) values ('comic'),('pastweek'),('currentweek'),('automation corner'),('uncategorized');
At this point, you are ready to run the app locally.
Once you are setup, from the next time onwards, all you need to do is
flask run
This assumes you have set the right environment variables in step 4 of the setup. To test that your setup works, please visit http://localhost:5000 and login. Then, try to add a single article via the form in the /articles page.
To track migrations, migrations folder have been added now, Next time onwards following steps needs to be followed:
- Update the
model.pyfile to make the changes. - Run
flask db migrate - Run
flask db upgrade
To add articles using POST method use the following:
- Set your api key in environment variable as
'API_KEY': '<YOURAPIKEY>' - Use the same api key for Request headers
'x-api-key': '<YOURAPIKEY>' - API Endpoint: POST
<base_url>/api/articles - Example curl command
curl -X POST http://localhost:5000/api/articles -H 'X-API-KEY: <YOUR_API_KEY>' -F 'url=http://exampleURL.com' -F 'category_id=2
Great Expectations is an open-source Python library to test data pipelines. It helps in validating and documenting data and thus maintaining data quality.
-
Install great_expectations:
pip install great_expectations -
Set the environment variables prefixed with
DB_, mentioned in great_expectations.yml -
Navigate to tests > data_validation > great_expectations directory:
cd tests/data_validation/great_expectations -
Run the checkpoint script. Navigate to newsletter_automation directory and run:
pytest tests/data_validation/great_expectations/utils/ -s -v -m checkpoint10amThis will trigger the Checkpoint and run the Expectation Suite against the MySQL table data as configured in the datasource. Please use the correct pytest marker to trigger the relevant checkpoint.
-
Results are stored in
great_expectations/uncommitted/data_docs/local_sitefolder. Navigate to the above directory using File Explorer. Open index.html, go to Validations tab and select your recent run. It will show details of what expectations have run, how many have passed/failed, failure details etc.