resolve #12 - exclude toots with certain hashtags

This commit is contained in:
Hugh Rundle 2020-04-04 18:28:21 +11:00
parent e3001255c6
commit f8d118bbbe
3 changed files with 15 additions and 4 deletions

View File

@ -25,10 +25,14 @@ This script requires Python3, the `mastodon.py` package and an API access token.
6. Set the base_url to match your mastodon server
7. Set the `days_to_keep` to the number of days you want to keep toots before deleting them
8. If you do **not** wish to keep all pinned toots regardless of age, change `save_pinned` to `False`
9. If there are any other toots you want to keep, put the ID numbers (without quotes) in the `toots_to_save` list, separated by commas. For example:
9. If there are any other toots you want to keep, put the ID numbers (without quotes) in the `toots_to_keep` list, separated by commas. For example:
`toots_to_save = [100029521330725397, 100013562864734780, 100044187305250752]`
10. You can keep toots with particular visibility (e.g. direct messages) by including that visibility in `visibility_to_keep`. For example the following would only delete public toots:
`toots_to_keep = [100029521330725397, 100013562864734780, 100044187305250752]`
10. If you want to keep toots with a particular hashtag, list each hashtag in the `hashtags_to_keep` set (omitting the `#`):
```python
hashtags_to_keep = {'introduction', 'announcement'}
```
11. You can keep toots with particular visibility (e.g. direct messages) by including that visibility in `visibility_to_keep`. For example the following would only delete public toots:
```python
visibility_to_keep = ['unlisted', 'private', 'direct']
```

View File

@ -51,6 +51,10 @@ timeline = mastodon.account_statuses(user_id, limit=40)
def checkToots(timeline, deleted_count=0):
for toot in timeline:
toot_tags = set()
for tag in toot.tags:
toot_tags.add(tag.name)
try:
if config.keep_pinned and hasattr(toot, "pinned") and toot.pinned:
print("📌 skipping pinned toot - " + str(toot.id))
@ -58,6 +62,8 @@ def checkToots(timeline, deleted_count=0):
print("💾 skipping saved toot - " + str(toot.id))
elif toot.visibility in config.visibility_to_keep:
print("👀 skipping " + toot.visibility + " toot - " + str(toot.id))
elif len(config.hashtags_to_keep.intersection(toot_tags)) > 0:
print("#️⃣ skipping toot with hashtag - " + str(toot.id))
elif cutoff_date > toot.created_at:
if hasattr(toot, "reblog") and toot.reblog:
print(

View File

@ -3,4 +3,5 @@ base_url = 'https://ausglam.space'
days_to_keep = 30
save_pinned = True
toots_to_save = []
visibility_to_keep = [] # options are: 'public', 'unlisted', 'private', 'direct'
hashtags_to_keep = {'introduction', 'announcement'} # comma separated Set as strings, e.g. 'introduction'
visibility_to_keep = ['private', 'unlisted'] # options are: 'public', 'unlisted', 'private', 'direct'