This simply takes Maple's work and adapts it for the ananas framework, allowing you to skip the cron jobs and manual posting.
Usage:
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.
Create a Mastodon account to be the ebooks bot.
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.
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.
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.)
Open config.cfg. Make the following changes:
Change domain to whatever your bot's instance is.
Paste your client key after client_id, your client secret after client_secret, and your access token after access_token.
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.
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:
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:
请发表评论