Skip to content

Commit e4c6f29

Browse files
committed
client search params
1 parent 1efbf57 commit e4c6f29

File tree

1 file changed

+78
-6
lines changed

1 file changed

+78
-6
lines changed

twarc/client2.py

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,37 @@ def _search(
118118
start_time,
119119
end_time,
120120
max_results,
121+
expansions,
122+
tweet_fields,
123+
user_fields,
124+
media_fields,
125+
poll_fields,
126+
place_fields,
121127
granularity=None,
122128
sleep_between=0,
129+
**kwargs,
123130
):
131+
params = {}
124132
if granularity:
125-
params = {}
133+
# Do not specify anything else when calling counts endpoint
126134
params["granularity"] = granularity
127135
else:
128-
params = expansions.EVERYTHING.copy()
136+
params["expansions"] = expansions if expansions else ",".join(EXPANSIONS)
137+
params["tweet.fields"] = (
138+
tweet_fields if tweet_fields else ",".join(TWEET_FIELDS)
139+
)
140+
params["user.fields"] = (
141+
user_fields if user_fields else ",".join(USER_FIELDS)
142+
)
143+
params["media.fields"] = (
144+
media_fields if media_fields else ",".join(MEDIA_FIELDS)
145+
)
146+
params["poll.fields"] = (
147+
poll_fields if poll_fields else ",".join(POLL_FIELDS)
148+
)
149+
params["place.fields"] = (
150+
place_fields if place_fields else ",".join(PLACE_FIELDS)
151+
)
129152

130153
params["query"] = query
131154

@@ -169,6 +192,12 @@ def search_recent(
169192
start_time=None,
170193
end_time=None,
171194
max_results=100,
195+
expansions=None,
196+
tweet_fields=None,
197+
user_fields=None,
198+
media_fields=None,
199+
poll_fields=None,
200+
place_fields=None,
172201
):
173202
"""
174203
Search Twitter for the given query in the last seven days,
@@ -195,7 +224,19 @@ def search_recent(
195224
"""
196225
url = "https://api.twitter.com/2/tweets/search/recent"
197226
return self._search(
198-
url, query, since_id, until_id, start_time, end_time, max_results
227+
url,
228+
query,
229+
since_id,
230+
until_id,
231+
start_time,
232+
end_time,
233+
max_results,
234+
expansions,
235+
tweet_fields,
236+
user_fields,
237+
media_fields,
238+
poll_fields,
239+
place_fields,
199240
)
200241

201242
@requires_app_auth
@@ -207,6 +248,12 @@ def search_all(
207248
start_time=None,
208249
end_time=None,
209250
max_results=100, # temp fix for #504
251+
expansions=None,
252+
tweet_fields=None,
253+
user_fields=None,
254+
media_fields=None,
255+
poll_fields=None,
256+
place_fields=None,
210257
):
211258
"""
212259
Search Twitter for the given query in the full archive,
@@ -248,6 +295,12 @@ def search_all(
248295
start_time,
249296
end_time,
250297
max_results,
298+
expansions,
299+
tweet_fields,
300+
user_fields,
301+
media_fields,
302+
poll_fields,
303+
place_fields,
251304
sleep_between=1.05,
252305
)
253306

@@ -287,7 +340,20 @@ def counts_recent(
287340
"""
288341
url = "https://api.twitter.com/2/tweets/counts/recent"
289342
return self._search(
290-
url, query, since_id, until_id, start_time, end_time, None, granularity
343+
url,
344+
query,
345+
since_id,
346+
until_id,
347+
start_time,
348+
end_time,
349+
max_results=None,
350+
expansions=None,
351+
tweet_fields=None,
352+
user_fields=None,
353+
media_fields=None,
354+
poll_fields=None,
355+
place_fields=None,
356+
granularity=granularity,
291357
)
292358

293359
@requires_app_auth
@@ -333,8 +399,14 @@ def counts_all(
333399
until_id,
334400
start_time,
335401
end_time,
336-
None,
337-
granularity,
402+
max_results=None,
403+
expansions=None,
404+
tweet_fields=None,
405+
user_fields=None,
406+
media_fields=None,
407+
poll_fields=None,
408+
place_fields=None,
409+
granularity=granularity,
338410
sleep_between=1.05,
339411
)
340412

0 commit comments

Comments
 (0)