Skip to content

Commit 2098078

Browse files
committed
Switch search to API v1.1 endpoint.
1 parent 02a43b7 commit 2098078

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

tweepy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = 'Joshua Roesslein'
1010
__license__ = 'MIT'
1111

12-
from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResult, ModelFactory, Category
12+
from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResults, ModelFactory, Category
1313
from tweepy.error import TweepError
1414
from tweepy.api import API
1515
from tweepy.cache import Cache, MemoryCache, FileCache

tweepy/api.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,10 @@ def test(self):
628628

629629
""" search """
630630
search = bind_api(
631-
search_api = True,
632-
path = '/search.json',
633-
payload_type = 'search_result', payload_list = True,
634-
allowed_param = ['q', 'lang', 'locale', 'rpp', 'page', 'since_id', 'geocode', 'show_user', 'max_id', 'since', 'until', 'result_type']
631+
path = '/search/tweets.json',
632+
payload_type = 'search_results',
633+
allowed_param = ['q', 'lang', 'locale', 'since_id', 'geocode', 'show_user', 'max_id', 'since', 'until', 'result_type']
635634
)
636-
search.pagination_mode = 'page'
637635

638636
""" trends/daily """
639637
trends_daily = bind_api(

tweepy/models.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,34 +209,20 @@ def destroy(self):
209209
return self._api.destroy_saved_search(self.id)
210210

211211

212-
class SearchResult(Model):
212+
class SearchResults(ResultSet):
213213

214214
@classmethod
215215
def parse(cls, api, json):
216-
result = cls()
217-
for k, v in json.items():
218-
if k == 'created_at':
219-
setattr(result, k, parse_search_datetime(v))
220-
elif k == 'source':
221-
setattr(result, k, parse_html_value(unescape_html(v)))
222-
else:
223-
setattr(result, k, v)
224-
return result
225-
226-
@classmethod
227-
def parse_list(cls, api, json_list, result_set=None):
228-
results = ResultSet()
229-
results.max_id = json_list.get('max_id')
230-
results.since_id = json_list.get('since_id')
231-
results.refresh_url = json_list.get('refresh_url')
232-
results.next_page = json_list.get('next_page')
233-
results.results_per_page = json_list.get('results_per_page')
234-
results.page = json_list.get('page')
235-
results.completed_in = json_list.get('completed_in')
236-
results.query = json_list.get('query')
237-
238-
for obj in json_list['results']:
239-
results.append(cls.parse(api, obj))
216+
results = SearchResults()
217+
metadata = json['search_metadata']
218+
results.max_id = metadata.get('max_id')
219+
results.since_id = metadata.get('since_id')
220+
results.refresh_url = metadata.get('refresh_url')
221+
results.completed_in = metadata.get('completed_in')
222+
results.query = metadata.get('query')
223+
224+
for status in json['statuses']:
225+
results.append(Status.parse(api, status))
240226
return results
241227

242228

@@ -414,7 +400,7 @@ class ModelFactory(object):
414400
direct_message = DirectMessage
415401
friendship = Friendship
416402
saved_search = SavedSearch
417-
search_result = SearchResult
403+
search_results = SearchResults
418404
category = Category
419405
list = List
420406
relation = Relation

0 commit comments

Comments
 (0)