Module: tooter¶
This module is a bit of a wrapper around the Mastodon.py library to call Mastodon API and fetch toots.
The idea is to create an object, a "Tooter," that encapsulates our conversation with one server. It basically takes a date, a hashtag, and a max. It starts "now" and goes backward in time until it gets a post that is too old or until it hits the max. It does assume that posts are returned in reverse chronological order. That's the only way it makes sense to stop at the first post that is too old.
Create a Tooter object that toots stuff. This is some of the oldest code in the project, and I'm not a great programmer. So some of this is probably a bit sloppy.
Tooter
¶
Bases: Mastodon
An object that represents all our interactions with a single server.
Source code in mastoscore/tooter.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
search_hashtag(hashtag, oldest_date, max=2000)
¶
Given a hashtag, search the public timeline for that hashtag. Yield pages of toots that are newer than oldest_date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hashtag
|
str
|
String of the hashtag to search for |
required |
oldest_date
|
datetime
|
Oldest date that we will accept |
required |
max
|
int
|
Maximum number of toots to fetch (default: 2000) |
2000
|
Returns:
| Type | Description |
|---|---|
Generator[list[dict[str, Any]]]
|
Yields pages of toots (up to 40 per page) as they are fetched. |
Source code in mastoscore/tooter.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |