aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py219
1 files changed, 3 insertions, 216 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 35b8444..0ded1cf 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -43,11 +43,13 @@ from .internals import Mastodon as Internals
43from .authentication import Mastodon as Authentication 43from .authentication import Mastodon as Authentication
44from .accounts import Mastodon as Accounts 44from .accounts import Mastodon as Accounts
45from .instance import Mastodon as Instance 45from .instance import Mastodon as Instance
46from .timeline import Mastodon as Timeline
47from .statuses import Mastodon as Statuses
46 48
47## 49##
48# The actual Mastodon class 50# The actual Mastodon class
49### 51###
50class Mastodon(Utility, Authentication, Accounts, Instance): 52class Mastodon(Utility, Authentication, Accounts, Instance, Timeline, Statuses):
51 """ 53 """
52 Thorough and easy to use Mastodon 54 Thorough and easy to use Mastodon
53 API wrapper in Python. 55 API wrapper in Python.
@@ -65,221 +67,6 @@ class Mastodon(Utility, Authentication, Accounts, Instance):
65 return Mastodon.__SUPPORTED_MASTODON_VERSION 67 return Mastodon.__SUPPORTED_MASTODON_VERSION
66 68
67 ### 69 ###
68 # Reading data: Timelines
69 ##
70 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
71 def timeline(self, timeline="home", max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
72 """
73 Fetch statuses, most recent ones first. `timeline` can be 'home', 'local', 'public',
74 'tag/hashtag' or 'list/id'. See the following functions documentation for what those do.
75
76 The default timeline is the "home" timeline.
77
78 Specify `only_media` to only get posts with attached media. Specify `local` to only get local statuses,
79 and `remote` to only get remote statuses. Some options are mutually incompatible as dictated by logic.
80
81 May or may not require authentication depending on server settings and what is specifically requested.
82
83 Returns a list of :ref:`status dicts <status dicts>`.
84 """
85 if max_id is not None:
86 max_id = self.__unpack_id(max_id, dateconv=True)
87
88 if min_id is not None:
89 min_id = self.__unpack_id(min_id, dateconv=True)
90
91 if since_id is not None:
92 since_id = self.__unpack_id(since_id, dateconv=True)
93
94 params_initial = locals()
95
96 if not local:
97 del params_initial['local']
98
99 if not remote:
100 del params_initial['remote']
101
102 if not only_media:
103 del params_initial['only_media']
104
105 if timeline == "local":
106 timeline = "public"
107 params_initial['local'] = True
108
109 params = self.__generate_params(params_initial, ['timeline'])
110 url = '/api/v1/timelines/{0}'.format(timeline)
111 return self.__api_request('GET', url, params)
112
113 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
114 def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
115 """
116 Convenience method: Fetches the logged-in user's home timeline (i.e. followed users and self). Params as in `timeline()`.
117
118 Returns a list of :ref:`status dicts <status dicts>`.
119 """
120 return self.timeline('home', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
121
122 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
123 def timeline_local(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False):
124 """
125 Convenience method: Fetches the local / instance-wide timeline, not including replies. Params as in `timeline()`.
126
127 Returns a list of :ref:`status dicts <status dicts>`.
128 """
129 return self.timeline('local', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media)
130
131 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
132 def timeline_public(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
133 """
134 Convenience method: Fetches the public / visible-network / federated timeline, not including replies. Params as in `timeline()`.
135
136 Returns a list of :ref:`status dicts <status dicts>`.
137 """
138 return self.timeline('public', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
139
140 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
141 def timeline_hashtag(self, hashtag, local=False, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, remote=False):
142 """
143 Convenience method: Fetch a timeline of toots with a given hashtag. The hashtag parameter
144 should not contain the leading #. Params as in `timeline()`.
145
146 Returns a list of :ref:`status dicts <status dicts>`.
147 """
148 if hashtag.startswith("#"):
149 raise MastodonIllegalArgumentError(
150 "Hashtag parameter should omit leading #")
151 return self.timeline('tag/{0}'.format(hashtag), max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
152
153 @api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS)
154 def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
155 """
156 Convenience method: Fetches a timeline containing all the toots by users in a given list. Params as in `timeline()`.
157
158 Returns a list of :ref:`status dicts <status dicts>`.
159 """
160 id = self.__unpack_id(id)
161 return self.timeline('list/{0}'.format(id), max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
162
163 @api_version("2.6.0", "2.6.0", _DICT_VERSION_CONVERSATION)
164 def conversations(self, max_id=None, min_id=None, since_id=None, limit=None):
165 """
166 Fetches a user's conversations.
167
168 Returns a list of :ref:`conversation dicts <conversation dicts>`.
169 """
170 if max_id is not None:
171 max_id = self.__unpack_id(max_id, dateconv=True)
172
173 if min_id is not None:
174 min_id = self.__unpack_id(min_id, dateconv=True)
175
176 if since_id is not None:
177 since_id = self.__unpack_id(since_id, dateconv=True)
178
179 params = self.__generate_params(locals())
180 return self.__api_request('GET', "/api/v1/conversations/", params)
181
182 ###
183 # Reading data: Statuses
184 ###
185 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
186 def status(self, id):
187 """
188 Fetch information about a single toot.
189
190 Does not require authentication for publicly visible statuses.
191
192 Returns a :ref:`status dict <status dict>`.
193 """
194 id = self.__unpack_id(id)
195 url = '/api/v1/statuses/{0}'.format(str(id))
196 return self.__api_request('GET', url)
197
198 @api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD)
199 def status_card(self, id):
200 """
201 Fetch a card associated with a status. A card describes an object (such as an
202 external video or link) embedded into a status.
203
204 Does not require authentication for publicly visible statuses.
205
206 This function is deprecated as of 3.0.0 and the endpoint does not
207 exist anymore - you should just use the "card" field of the status dicts
208 instead. Mastodon.py will try to mimic the old behaviour, but this
209 is somewhat inefficient and not guaranteed to be the case forever.
210
211 Returns a :ref:`card dict <card dict>`.
212 """
213 if self.verify_minimum_version("3.0.0", cached=True):
214 return self.status(id).card
215 else:
216 id = self.__unpack_id(id)
217 url = '/api/v1/statuses/{0}/card'.format(str(id))
218 return self.__api_request('GET', url)
219
220 @api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT)
221 def status_context(self, id):
222 """
223 Fetch information about ancestors and descendants of a toot.
224
225 Does not require authentication for publicly visible statuses.
226
227 Returns a :ref:`context dict <context dict>`.
228 """
229 id = self.__unpack_id(id)
230 url = '/api/v1/statuses/{0}/context'.format(str(id))
231 return self.__api_request('GET', url)
232
233 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
234 def status_reblogged_by(self, id):
235 """
236 Fetch a list of users that have reblogged a status.
237
238 Does not require authentication for publicly visible statuses.
239
240 Returns a list of :ref:`account dicts <account dicts>`.
241 """
242 id = self.__unpack_id(id)
243 url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id))
244 return self.__api_request('GET', url)
245
246 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
247 def status_favourited_by(self, id):
248 """
249 Fetch a list of users that have favourited a status.
250
251 Does not require authentication for publicly visible statuses.
252
253 Returns a list of :ref:`account dicts <account dicts>`.
254 """
255 id = self.__unpack_id(id)
256 url = '/api/v1/statuses/{0}/favourited_by'.format(str(id))
257 return self.__api_request('GET', url)
258
259 ###
260 # Reading data: Scheduled statuses
261 ###
262 @api_version("2.7.0", "2.7.0", _DICT_VERSION_SCHEDULED_STATUS)
263 def scheduled_statuses(self):
264 """
265 Fetch a list of scheduled statuses
266
267 Returns a list of :ref:`scheduled status dicts <scheduled status dicts>`.
268 """
269 return self.__api_request('GET', '/api/v1/scheduled_statuses')
270
271 @api_version("2.7.0", "2.7.0", _DICT_VERSION_SCHEDULED_STATUS)
272 def scheduled_status(self, id):
273 """
274 Fetch information about the scheduled status with the given id.
275
276 Returns a :ref:`scheduled status dict <scheduled status dict>`.
277 """
278 id = self.__unpack_id(id)
279 url = '/api/v1/scheduled_statuses/{0}'.format(str(id))
280 return self.__api_request('GET', url)
281
282 ###
283 # Reading data: Polls 70 # Reading data: Polls
284 ### 71 ###
285 @api_version("2.8.0", "2.8.0", _DICT_VERSION_POLL) 72 @api_version("2.8.0", "2.8.0", _DICT_VERSION_POLL)
Powered by cgit v1.2.3 (git 2.41.0)