Skip to content

danwahl/predictable-news-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

predictable-news-bot

A bot that tweets daily updates about questions on Metaforecast, inspired by Astral Codex Ten.

See also:

Python setup

  1. Create a new Python 3.11 virtual environment
  2. Activate the environment
  3. Install the required packages
$ pyenv local 3.11.2
$ python -m venv env
$ source env/bin/activate
(env) $ pip install -r requirements.txt

Twitter authentication

  1. Sign up for a developer account on Twitter using your "regular" account (e.g. fakedrwahl)
  2. Apply for "Elevated access" (which is required to access parts of the v2 API functionality)
  3. In the Developer Portal, create a new Project (e.g. "Predictable News") and corresponding App (e.g. "predictable-news-bot")
  4. Copy the API Key and Secret to a local .env file under CONSUMER_KEY and CONSUMER_SECRET (don't commit this file to GitHub!)
  5. Under "User authentication settings," enable OAuth 1.0a with "Read and write" permissions (Callback and Website URLs are required but not used, so just enter e.g. http://predictable.news)
  6. Log into Twitter under the "tweeting" account (e.g. PredictableNews)
  7. Activate the Python virtual environment created above
  8. Run auth.py script, open the authorization url, input the provided pin, and copy the resulting ACCESS_TOKEN and ACCESS_TOKEN_SECRET to the .env file from step 4
$ source env/bin/activate
(env) $ python auth.py
https://api.twitter.com/oauth/authorize?oauth_token=...

...

Input PIN: 1234567
Add the following to your .env file:
ACCESS_TOKEN=...
ACCESS_TOKEN_SECRET=...

Main usage

Follow the Twitter authentication steps above to create a local .env file. Then the main.py script can then be run as follows:

$ source env/bin/activate
(env) $ python main.py --help
usage: main.py [-h] [-c CHANGE] [-d] [-t]

optional arguments:
  -h, --help            show this help message and exit
  -c CHANGE, --change CHANGE
                        probability change threshold for tweeting (default: 0.05)
  -d, --debug           enable debug logging (default: False)
  -t, --tweet           actually send tweets (default: False)

Deploy on GitHub

Add the secrets from your local .env file (CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, and ACCESS_TOKEN_SECRET) to your repository on GitHub as described here.

Optionally, adjust the .github/workflows/main.yml file schedule to run at the desired time.

About

All the News That's Fit to Predict

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages