diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 444c12d..7561cea 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -179,6 +179,7 @@ class Mastodon: | |||
179 | __DICT_VERSION_PUSH_NOTIF = "2.4.0" | 179 | __DICT_VERSION_PUSH_NOTIF = "2.4.0" |
180 | __DICT_VERSION_FILTER = "2.4.3" | 180 | __DICT_VERSION_FILTER = "2.4.3" |
181 | __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) | 181 | __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) |
182 | __DICT_VERSION_SCHEDULED_STATUS = bigger_version("2.7.0", __DICT_VERSION_STATUS) | ||
182 | 183 | ||
183 | ### | 184 | ### |
184 | # Registering apps | 185 | # Registering apps |
@@ -1300,10 +1301,11 @@ class Mastodon: | |||
1300 | ### | 1301 | ### |
1301 | # Writing data: Statuses | 1302 | # Writing data: Statuses |
1302 | ### | 1303 | ### |
1303 | @api_version("1.0.0", "2.4.3", __DICT_VERSION_STATUS) | 1304 | @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) |
1304 | def status_post(self, status, in_reply_to_id=None, media_ids=None, | 1305 | def status_post(self, status, in_reply_to_id=None, media_ids=None, |
1305 | sensitive=False, visibility=None, spoiler_text=None, | 1306 | sensitive=False, visibility=None, spoiler_text=None, |
1306 | language=None, idempotency_key=None, content_type=None): | 1307 | language=None, idempotency_key=None, content_type=None, |
1308 | scheduled_at=None): | ||
1307 | """ | 1309 | """ |
1308 | Post a status. Can optionally be in reply to another status and contain | 1310 | Post a status. Can optionally be in reply to another status and contain |
1309 | media. | 1311 | media. |
@@ -1341,7 +1343,11 @@ class Mastodon: | |||
1341 | if you call it with the same `idempotency_key`, only one status will | 1343 | if you call it with the same `idempotency_key`, only one status will |
1342 | be created. | 1344 | be created. |
1343 | 1345 | ||
1344 | Specify 'content_type' to set the content type of your post on Pleroma. | 1346 | Pass a datetime as `scheduled_at` to schedule the toot for a specific time |
1347 | (the time must be at least 5 minutes into the future). If this is passed, | ||
1348 | status_post returns a `scheduled toot dict`_ instead. | ||
1349 | |||
1350 | Specify `content_type` to set the content type of your post on Pleroma. | ||
1345 | It accepts 'text/plain' (default), 'text/markdown', and 'text/html'. | 1351 | It accepts 'text/plain' (default), 'text/markdown', and 'text/html'. |
1346 | This parameter is not supported on Mastodon servers, but will be | 1352 | This parameter is not supported on Mastodon servers, but will be |
1347 | safely ignored if set. | 1353 | safely ignored if set. |
@@ -1351,6 +1357,9 @@ class Mastodon: | |||
1351 | if in_reply_to_id != None: | 1357 | if in_reply_to_id != None: |
1352 | in_reply_to_id = self.__unpack_id(in_reply_to_id) | 1358 | in_reply_to_id = self.__unpack_id(in_reply_to_id) |
1353 | 1359 | ||
1360 | if scheduled_at != None: | ||
1361 | scheduled_at = scheduled_at.isoformat() | ||
1362 | |||
1354 | params_initial = locals() | 1363 | params_initial = locals() |
1355 | 1364 | ||
1356 | # Validate visibility parameter | 1365 | # Validate visibility parameter |
@@ -1395,7 +1404,7 @@ class Mastodon: | |||
1395 | params = self.__generate_params(params_initial, ['idempotency_key']) | 1404 | params = self.__generate_params(params_initial, ['idempotency_key']) |
1396 | return self.__api_request('POST', '/api/v1/statuses', params, headers = headers) | 1405 | return self.__api_request('POST', '/api/v1/statuses', params, headers = headers) |
1397 | 1406 | ||
1398 | @api_version("1.0.0", "2.4.3", __DICT_VERSION_STATUS) | 1407 | @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) |
1399 | def toot(self, status): | 1408 | def toot(self, status): |
1400 | """ | 1409 | """ |
1401 | Synonym for `status_post()`_ that only takes the status text as input. | 1410 | Synonym for `status_post()`_ that only takes the status text as input. |
@@ -1406,9 +1415,10 @@ class Mastodon: | |||
1406 | """ | 1415 | """ |
1407 | return self.status_post(status) | 1416 | return self.status_post(status) |
1408 | 1417 | ||
1409 | @api_version("1.0.0", "2.4.3", __DICT_VERSION_STATUS) | 1418 | @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) |
1410 | def status_reply(self, to_status, status, media_ids=None, sensitive=False, visibility=None, | 1419 | def status_reply(self, to_status, status, media_ids=None, sensitive=False, visibility=None, |
1411 | spoiler_text=None, language=None, idempotency_key=None, untag=False): | 1420 | spoiler_text=None, language=None, idempotency_key=None, content_type=None, |
1421 | scheduled_at=None, untag=False): | ||
1412 | """ | 1422 | """ |
1413 | Helper function - acts like status_post, but prepends the name of all | 1423 | Helper function - acts like status_post, but prepends the name of all |
1414 | the users that are being replied to to the status text and retains | 1424 | the users that are being replied to to the status text and retains |
@@ -1440,7 +1450,8 @@ class Mastodon: | |||
1440 | 1450 | ||
1441 | return self.status_post(status, in_reply_to_id = to_status.id, media_ids = media_ids, sensitive = sensitive, | 1451 | return self.status_post(status, in_reply_to_id = to_status.id, media_ids = media_ids, sensitive = sensitive, |
1442 | visibility = visibility, spoiler_text = spoiler_text, language = language, | 1452 | visibility = visibility, spoiler_text = spoiler_text, language = language, |
1443 | idempotency_key = idempotency_key) | 1453 | idempotency_key = idempotency_key, content_type = content_type, |
1454 | scheduled_at = scheduled_at) | ||
1444 | 1455 | ||
1445 | @api_version("1.0.0", "1.0.0", "1.0.0") | 1456 | @api_version("1.0.0", "1.0.0", "1.0.0") |
1446 | def status_delete(self, id): | 1457 | def status_delete(self, id): |
@@ -1540,6 +1551,17 @@ class Mastodon: | |||
1540 | return self.__api_request('POST', url) | 1551 | return self.__api_request('POST', url) |
1541 | 1552 | ||
1542 | ### | 1553 | ### |
1554 | # Writing data: Scheduled statuses | ||
1555 | ### | ||
1556 | @api_version("2.7.0", "2.7.0", __DICT_VERSION_SCHEDULED_STATUS) | ||
1557 | def update_scheduled_status(self, id, scheduled_at): | ||
1558 | scheduled_at = scheduled_at.isoformat() | ||
1559 | id = self.__unpack_id(id) | ||
1560 | self.__generate_params(locals(), ['id']) | ||
1561 | url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) | ||
1562 | return self.__api_request('PUT', url, params) | ||
1563 | |||
1564 | ### | ||
1543 | # Writing data: Notifications | 1565 | # Writing data: Notifications |
1544 | ### | 1566 | ### |
1545 | @api_version("1.0.0", "1.0.0", "1.0.0") | 1567 | @api_version("1.0.0", "1.0.0", "1.0.0") |
@@ -2303,7 +2325,7 @@ class Mastodon: | |||
2303 | """ | 2325 | """ |
2304 | Parse dates in certain known json fields, if possible. | 2326 | Parse dates in certain known json fields, if possible. |
2305 | """ | 2327 | """ |
2306 | known_date_fields = ["created_at", "week", "day", "expires_at"] | 2328 | known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at"] |
2307 | for k, v in json_object.items(): | 2329 | for k, v in json_object.items(): |
2308 | if k in known_date_fields: | 2330 | if k in known_date_fields: |
2309 | if v != None: | 2331 | if v != None: |