@@ -13,6 +13,7 @@ class API:
13
13
_product : str = None
14
14
_endpoint : str = None
15
15
_has_params : bool = None
16
+ _pagination : bool = False
16
17
_params : dict = {}
17
18
_stream : bool = None
18
19
_data : dict = None
@@ -72,15 +73,24 @@ def connect(self) -> dict:
72
73
if self ._has_params :
73
74
self ._params = self ._query ()
74
75
75
- response = self .api (
76
- method = "GET" ,
77
- endpoint = self ._endpoint ,
78
- stream = self ._stream ,
79
- params = self ._params ,
80
- )
81
- response .raise_for_status ()
82
- for response_lines in response .iter_lines ():
83
- yield json .loads (response_lines )
76
+ data = None
77
+
78
+ while True :
79
+ response = self .api (
80
+ method = "GET" ,
81
+ endpoint = self ._endpoint ,
82
+ stream = self ._stream ,
83
+ params = self ._params ,
84
+ )
85
+ response .raise_for_status ()
86
+ for response_lines in response .iter_lines ():
87
+ data = json .loads (response_lines )
88
+ yield data
89
+
90
+ if not self ._pagination :
91
+ break
92
+ self ._params ["next_token" ] = data ["meta" ]["next_token" ]
93
+
84
94
except Exception as e :
85
95
raise e
86
96
@@ -222,6 +232,7 @@ class RecentSearch(API):
222
232
"start_time" ,
223
233
"until_id" ,
224
234
]
235
+ _pagination = True
225
236
226
237
227
238
class TweetLookUp (API ):
@@ -278,20 +289,20 @@ def hide_replies(tweet: str, hidden: dict) -> json:
278
289
Hides specific tweets from a conversation
279
290
:params: tweet: str = url of the tweet to hide
280
291
:params: hidden: dict = {"hidden: True}
281
-
282
- :returns json
283
-
292
+
293
+ :returns json
294
+
284
295
Usage:
285
-
296
+
286
297
hide_replies(
287
298
tweet = 'https://twitter.com/saadmanrafat_/status/1328288598106443776',
288
299
{"hidden: True}
289
300
)
290
-
291
- response =
301
+
302
+ response =
292
303
{
293
304
"data": {
294
- "hidden": true
305
+ "hidden": true
295
306
}
296
307
}
297
308
"""
@@ -310,4 +321,4 @@ def hide_replies(tweet: str, hidden: dict) -> json:
310
321
auth = auth ,
311
322
data = json .dumps (hidden ),
312
323
)
313
- return json .dumps (response .json (), indent = 4 )
324
+ return json .dumps (response .json (), indent = 4 )
0 commit comments