A Twitter bot that tweets, if the current date in ISO 8601 format, without the hyphens (e.g., 20170913), is a prime number. For example, on September 1, 2017, it would tweet
Today 20170901 is a prime
a Chen prime
an Eisenstein prime
a Pythagorean prime
has a twin prime
has a cousin prime.
If the current date is not a prime number, it will tweet the factorization of the ISO-8601-formatted date. For example,
Today 20180503 is not a prime
20180503 = 7^2 x 37 x 11131
- Python 3.6 or above
- Unix/Linux environment with the 'date' command and the Pari/GP
calculator. On Ubuntu,
apt install pari-gp
will get Pari/GP installed. - The 'prime_classes' project on Github.
Similar to that described in https://github.com/syncom/twitbot-tih.
-
Create a Twitter app and obtain the API Key, API Secret, Access Token, and Access Token Secret for the app. This can be done by following the instructions at: https://developer.twitter.com/en/docs/twitter-api/getting-started/getting-access-to-the-twitter-api. On 20230429, we started to see API authentication errors, and a message "This app has violated Twitter rules and policies" on the Twitter app setting page. According to this discussion, we signed up for the Free tier of "Twitter API v2" (at no cost), and clicked button "downgrade to free"; this resolved the auth issue. You may also need to put the Twitter app under a "project" for better organization and monitoring of the app.
-
Clone this repository with the submodule and change directory to it. Set up Python3 virtual environment.
git clone --recursive https://github.com/syncom/twitbot-iwpt.git cd twitbot-iwpt # Set up virtualenv and pip install packages make install
-
Set up authentication and authorization secrets by following this Getting Started guide. The preferred way is to set environment variables
IWPT_API_KEY
,IWPT_API_SECRET
,IWPT_ACCESS_TOKEN
, andIWPT_ACCESS_SECRET
with API Key, API Secret, Access Token, and Access Token Secret values obtained in the first step. Alternatively, one can override the corresponding strings in the file '.auth' with appropriate secret strings. When any of the aformetioned environment variables are set, they take precedence over values in the.auth
file. -
Run
./iwpt_bot_run.sh
to tweet. Note that it only tweets when the ISO 8601 formatted string for today's date is a prime number. The log files for each day's tweet can be found in the 'logs' subdirectory. They keep state of the primality info and the tweet status, and are used by our application to make tweeting decisions. -
(Optional) Create a cron job to invoke the bot multiple times a day, to account for sporadic connecitivity issues.