This project consists of a set of scripts that can be used to automate the process of creating and deleting cron jobs. There are two folders flask
and nodejs
, each containing different cron jobs implemented using different packages for managing the cron job schedules with specific functionalities.
- Flask
- APScheduler - A light but powerful in-process task scheduler that lets you schedule functions (or any other python callables) to be executed at times of your choosing.
- Flask Mail - A package for Flask that makes it easy to send emails.
- NodeJS and Express
- node-cron - A package for Node.js that allows you to schedule cron jobs.
- nodemailer - A module for Node.js applications to allow email sending.
- Twilio - A module for Node.js applications to allow SMS sending.
- OpenWeatherMap - An API for getting weather updates.
Download the project code locally Fork the project repository and clone your forked repository to your machine.
The flask
folder contains Flask-based cron jobs responsible for web scraping and sending emails. The APScheduler
package is used to schedule these cron jobs, BeautifulSoup
for web scraping and Flask-Mail
for sending emails .The cron jobs are:
- Demo - This is a simple cron job that runs at regular intervals, specifically every second. It can be used as a template for creating other cron jobs.
- Google Career Scraper Cron Job - This cron job scrapes Google Careers 9am every Monday and sends an email to a given recipient.
- Variety News Scraper Cron Job - This cron job scrapes Variety news every day and sends an email to a given recipient.
The nodejs
folder contains three cron jobs. The node-cron
package is used to schedule these cron jobs. The cron jobs are:
demo.js
- This is a simple cron job that runs at regular intervals, specifically every 2 seconds. It can be used as a template for creating other cron jobs.- Email Cron Job - This cron job sends an email every 5 seconds, demonstrating how to use node-cron to send emails periodically. It uses the
nodemailer
package to send emails. - Weather SMS Cron Job - This cron job sends an SMS of the weather update using Twilio every weekday at 9:45 AM. It uses the Twilio API to send SMS messages.
Navigate to the flask
folder.
- Create a virtual environment for the project
virtualenv venv
- Activate the virtual environment
source venv/bin/activate
- Install the dependencies
pip install -r requirements.txt
- Run the application
python app.py
- Open the application in your browser
http://localhost:5000
- To stop the application, press
Ctrl + C
Navigate to the nodejs
folder.
- Install the dependencies
npm install
- Run the application
npm start
- Open the application in your browser
http://localhost:3000
- To stop the application, press
Ctrl + C
Before running the application, you need to configure the following environment variables:
MAIL_USERNAME
- The email address of the senderMAIL_PASSWORD
- The password of the sender's email address
Create a .env
file at the flask
level and add the variables to it (otherwise hard code their strings in config.py
file).
MAIL_USERNAME=your_email_address
MAIL_PASSWORD=your_email_password
Other variables that can be updated include:
MAIL_RECIPIENT
- The email address of the recipient
Before running the application, you need to configure the following environment variables:
EMAILUSER
- The email address of the senderEMAILPASS
- The password of the sender's email addressTWILIO_ACCOUNT_SID
- The Twilio account SIDTWILIO_AUTH_TOKEN
- The Twilio auth tokenTWILIO_PHONE_NUMBER
- The Twilio phone numberWEATHER_API_KEY
- The OpenWeatherMap API key
Create a .env
file at the nodejs
level and add the variables to it (otherwise hard code their strings in their respective files).
Other variables that can be updated include:
MAIL_RECIPIENT
- The email address of the recipientRECIPIENT_PHONE_NUMBER
- The recipient's phone number
/
- The home page/demo_job
- The endpoint that starts the demo cron job/job_listings
- The endpoint that starts the Google Careers cron job/news
- The endpoint that starts the Variety News cron job/stop_job/<job_id>
- The endpoint that stops the cron job with the given job ID/stop_jobs
- The endpoint that stops all the cron jobs
/startmail
- The endpoint that starts the email cron job/startsms
- The endpoint that starts the weather cron job/stopmail
- The endpoint that stops the email cron job/stopsms
- The endpoint that stops the weather cron job/stopall
- The endpoint that stops all the cron jobs
Note - Curl commands can be used to start and stop the cron jobs. For example, to start the flask demo cron job, run the following command:
curl http://localhost:5000/demo_job
To stop the demo cron job, run the following command:
curl http://localhost:5000/stop_job/demo_job
Precious Michael - preciousmichael