Follow my Threads profile!
fetch_and_post_earthquake.py
is run via a cron job on Dreamhost that is scheduled to run every 5 minutes.
fetch_new_earthquakes()
gets the latest data from the USGS API. The script monitors earthquakes within a 300-mile radius and filters them based on distance and magnitude:
- Within 25 miles: Reports ALL earthquakes
- 25-50 miles: Reports earthquakes M2.0 and above
- 50-100 miles: Reports earthquakes M4.0 and above
- 100-200 miles: Reports earthquakes M5.0 and above
- 200-300 miles: Reports earthquakes M7.0 and above
post_to_threads()
takes the earthquake data and calls the threads API to publish a post. I include the USGS link to the earthquake details plus a google maps link to the coordinates of the earthquake epicenter.
I also schedule th_access_token.py
to be a cron job that's run every month to keep the access token valid.
-
Clone the repository:
git clone https://github.com/0xjessel/earthquake-bot.git cd earthquake-bot
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env.local
file:- Copy the
.env.example
file to create your own environment configuration:cp .env.example .env.local
- Copy the
-
Edit the
.env.local
file:- Open
.env.local
in a text editor and fill in the required values
- Open
-
Run the script
python fetch_and_post_earthquake.py
- To update the cron job on dreamhost server
scp fetch_and_post_earthquake.py meltedxice@iad1-shared-b8-41.dreamhost.com:~/cron_jobs/ba-earthquake-bot/
- Update the .env.local file if it changed
What other bots can I make hmm..