aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/timeline.py')
-rw-r--r--mastodon/timeline.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/mastodon/timeline.py b/mastodon/timeline.py
new file mode 100644
index 0000000..b5a4068
--- /dev/null
+++ b/mastodon/timeline.py
@@ -0,0 +1,121 @@
1from .versions import _DICT_VERSION_STATUS, _DICT_VERSION_CONVERSATION
2from .error import MastodonIllegalArgumentError, MastodonNotFoundError
3from .utility import api_version
4
5from .internals import Mastodon as Internals
6
7class Mastodon(Internals):
8 ###
9 # Reading data: Timelines
10 ##
11 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
12 def timeline(self, timeline="home", max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
13 """
14 Fetch statuses, most recent ones first. `timeline` can be 'home', 'local', 'public',
15 'tag/hashtag' or 'list/id'. See the following functions documentation for what those do.
16
17 The default timeline is the "home" timeline.
18
19 Specify `only_media` to only get posts with attached media. Specify `local` to only get local statuses,
20 and `remote` to only get remote statuses. Some options are mutually incompatible as dictated by logic.
21
22 May or may not require authentication depending on server settings and what is specifically requested.
23
24 Returns a list of :ref:`status dicts <status dicts>`.
25 """
26 if max_id is not None:
27 max_id = self.__unpack_id(max_id, dateconv=True)
28
29 if min_id is not None:
30 min_id = self.__unpack_id(min_id, dateconv=True)
31
32 if since_id is not None:
33 since_id = self.__unpack_id(since_id, dateconv=True)
34
35 params_initial = locals()
36
37 if not local:
38 del params_initial['local']
39
40 if not remote:
41 del params_initial['remote']
42
43 if not only_media:
44 del params_initial['only_media']
45
46 if timeline == "local":
47 timeline = "public"
48 params_initial['local'] = True
49
50 params = self.__generate_params(params_initial, ['timeline'])
51 url = '/api/v1/timelines/{0}'.format(timeline)
52 return self.__api_request('GET', url, params)
53
54 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
55 def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
56 """
57 Convenience method: Fetches the logged-in user's home timeline (i.e. followed users and self). Params as in `timeline()`.
58
59 Returns a list of :ref:`status dicts <status dicts>`.
60 """
61 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)
62
63 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
64 def timeline_local(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False):
65 """
66 Convenience method: Fetches the local / instance-wide timeline, not including replies. Params as in `timeline()`.
67
68 Returns a list of :ref:`status dicts <status dicts>`.
69 """
70 return self.timeline('local', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media)
71
72 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
73 def timeline_public(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
74 """
75 Convenience method: Fetches the public / visible-network / federated timeline, not including replies. Params as in `timeline()`.
76
77 Returns a list of :ref:`status dicts <status dicts>`.
78 """
79 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)
80
81 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
82 def timeline_hashtag(self, hashtag, local=False, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, remote=False):
83 """
84 Convenience method: Fetch a timeline of toots with a given hashtag. The hashtag parameter
85 should not contain the leading #. Params as in `timeline()`.
86
87 Returns a list of :ref:`status dicts <status dicts>`.
88 """
89 if hashtag.startswith("#"):
90 raise MastodonIllegalArgumentError(
91 "Hashtag parameter should omit leading #")
92 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)
93
94 @api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS)
95 def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
96 """
97 Convenience method: Fetches a timeline containing all the toots by users in a given list. Params as in `timeline()`.
98
99 Returns a list of :ref:`status dicts <status dicts>`.
100 """
101 id = self.__unpack_id(id)
102 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)
103
104 @api_version("2.6.0", "2.6.0", _DICT_VERSION_CONVERSATION)
105 def conversations(self, max_id=None, min_id=None, since_id=None, limit=None):
106 """
107 Fetches a user's conversations.
108
109 Returns a list of :ref:`conversation dicts <conversation dicts>`.
110 """
111 if max_id is not None:
112 max_id = self.__unpack_id(max_id, dateconv=True)
113
114 if min_id is not None:
115 min_id = self.__unpack_id(min_id, dateconv=True)
116
117 if since_id is not None:
118 since_id = self.__unpack_id(since_id, dateconv=True)
119
120 params = self.__generate_params(locals())
121 return self.__api_request('GET', "/api/v1/conversations/", params)
Powered by cgit v1.2.3 (git 2.41.0)