randimgbot
Pick a random image and toot or tweet it.
Example
Randimgbot powers @FlagFacts@botsin.space on Mastodon and @FlagFacts on Twitter.
Set up Mastodon
Create an account at:
https://botsin.space/auth/sign_up
Follow https://gist.github.com/aparrish/661fca5ce7b4882a8c6823db12d42d26 to create a
client ID, client secret, and access token, and store in YAML file. See
data/randimgbot_example.yaml
.
Set up Twitter
Create and authorise an app with (read and) write access at:
https://dev.twitter.com/apps/new
Store credentials in YAML file. See data/randimgbot_example.yaml
.
Install dependencies
pip install -r requirements.txt
Run it
Call something like:
python randimgbot.py -y path/to/randimgbot.yaml -i path/to/dir/full/of/images/*.jpg -t "Random thing: {0} #randomthing {1}"
- Add
--mastodon
to post to Mastodon. - Add
--twitter
to post to Twitter.
Where {0}
will be replaced with a name taken from the filename, and {1}
is a hashtag
from the name. Either or both can be omitted.
Alternatively with a JSON file:
python randimgbot.py -y path/to/randimgbot.yaml -i data/randimgbot_example.json -t "Random thing: {0} #randomthing {1}"
Where the JSON file looks something like data/randimgbot_example.json:
{
"image1.jpg": "Description 1",
"image2.jpg": "Description 2\nLine 2"
}
By default it will only tweet randomly 1/12 times. Change this denominator with
--chance
.
Check full options with:
python randimgbot.py -h