Skip to content

joyeusenoelle/ananas-ebooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ananas-ebooks

Based on Maple's mastodon-ebooks.py.

This simply takes Maple's work and adapts it for the ananas framework, allowing you to skip the cron jobs and manual posting.

Usage:

  1. In the directory where ananas-ebooks is installed, run pip3 install -r requirements.txt to make sure you have all the requirements for the bot.
  2. Create a Mastodon account to be the ebooks bot.
  3. In Mastodon, use your bot account to follow each account you want to scrape to create your bot. DO NOT follow any accounts you don't want to scrape.
  4. In Mastodon, under Preferences > Development, create a new app for the bot. You can just call it "Ebooks" and leave "Application Website" blank. Do not change the Redirect URI.
  5. On the next screen, click on the name you gave your bot ("Ebooks" or something else). You'll get a client key, client secret, and access token. (Alternately, you can use a script like this to generate user secrets to be used by the ebooks script.)
  6. Open config.cfg. Make the following changes:
    1. Change domain to whatever your bot's instance is.
    2. Paste your client key after client_id, your client secret after client_secret, and your access token after access_token.
    3. By default, your bot will not scrape toots that are replies to other users. set exclude_replies = False if you want your bot to scrape replies in addition to "raw" toots.
  7. You're done! Type ananas config.cfg into your command line and watch your bot spring into action. It will start by scraping each account you've followed, then toot once each hour and look for replies so it can toot back.

If you want to manually re-scrape toots from your followed accounts, just stop the bot (with Ctrl-C) and start it again; it will check for new toots every time it starts up. Otherwise, your bot will automatically re-scrape the accounts it follows every 24 hours.

What settings can I change in config.cfg?

  • bot_name: If you're just running one bot, you can ignore this. If you're running more than one bot under the same ananas config, you should give each bot its own bot_name. This will allow each bot to maintain its own separate corpus and not cross-pollinate between bots.
  • exclude_replies: If this is True, when your bot is scraping the accounts it follows, it will ignore all toots that are replies to someone else. (This does not affect toots where the target user is starting a conversation - just where they're replying to someone.) Default: True.
  • reply_to_mentions: If this is True, your bot will reply with an auto-generated toot when someone mentions it. Default: True.
  • max_replies: Limits the number of times your bot will reply to a given person within a 5-minute period. Among other things, this prevents pairs of bots from accidentally getting caught in a loop. You can set this to -1 to have your bot ignore this feature and keep replying no matter what. Default: 3.
  • visibility: This affects the default visibility setting for your bot. Default: unlisted. The options are:
    • public: Your bot's toots will show up to everyone and will be posted on the public timelines.
    • unlisted: Your bot's toots will show up to everyone but will not be posted on the public timelines.
    • private: Your bot's toots will only be visible to people who follow your bot.
    • direct: Your bot's toots will only be visible to your bot. (This is not recommended!)

If the setting you give for visibility isn't one of those four options, it will default to unlisted.

Why do I have to follow everyone I want to scrape? Can't I just give it a list of usernames?

It's an anti-harassment measure. This way, if you want to make an ebooks bot of someone's toots, they're notified that the bot exists.

What if I already have an ananas bot running and I'd like to run them in tandem?

Just copy ebooks.py and requirements.txt into that bot's directory, and modify that config.cfg to have an [EBOOKS] section as described in step 6 above. ananas bots play very nicely with each other.

If you've already scraped some accounts and want to keep that data, copy over accts.json, model.json, and the corpus directory too. All that data will stay intact the next time you launch ananas.

This has been running for a long time, and I've tooted a lot since then. How do I get my new toots into the corpus?

The bot automatically scrapes new toots from its followed accounts once a day at 2:15 AM (to minimize collision with other tasks).

What if I want my bot to toot at a different time?

I'd love to be able to include this in the config.cfg file, but for various technical reasons it's not possible right now. Instead, you'll have to actually open up ebooks.py.

In ebooks.py, go to line 129. You'll see this:

@hourly(minute=0)

If you want your bot to post once an hour, but not on the hour, change the value of minute. For example, if you want your bot to post at 12:15, 1:15, 2:15, etc., change it to minute=15.

If you want your bot to post more than once an hour, just add another line. For example:

@hourly(minute=12)
@hourly(minute=42)
def toot(self):
  ...

will post every half-hour, at XX:12 and at XX:42.

If you want your bot to post less than once an hour, change @hourly to @daily. By default, this will make it post once a day, but like @hourly, you can stack them up. To post every four hours, you might do:

@daily(hour=0, minute=15)
@daily(hour=4, minute=15)
@daily(hour=8, minute=15)
@daily(hour=12, minute=15)
@daily(hour=16, minute=15)
@daily(hour=20, minute=15)
def toot(self):
  ...

Note how that uses 24-hour time.

You can see more details at the ananas repo.

I don't want my bot to reply to people, I just want it to post.

In config.cfg, change reply_to_mentions to False.

About

Python ebooks-style bot for Mastodon, now with Ananas

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages