Skip to content

Commit fdc0f70

Browse files
committed
Merge pull request tweepy#296 from tweepy/search-v1.1
Change API.search() to use endpoint v1.1
2 parents 4d75a02 + aedd73c commit fdc0f70

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
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: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -229,33 +229,18 @@ def destroy(self):
229229
return self._api.destroy_saved_search(self.id)
230230

231231

232-
class SearchResult(Model):
232+
class SearchResults(ResultSet):
233233

234234
@classmethod
235235
def parse(cls, api, json):
236-
result = cls()
237-
for k, v in json.items():
238-
if k == 'created_at':
239-
setattr(result, k, parse_search_datetime(v))
240-
elif k == 'source':
241-
setattr(result, k, parse_html_value(unescape_html(v)))
242-
else:
243-
setattr(result, k, v)
244-
return result
245-
246-
@classmethod
247-
def parse_list(cls, api, json_list, result_set=None):
248-
results = ResultSet(json_list.get('max_id',
249-
json_list.get('since_id')))
250-
results.refresh_url = json_list.get('refresh_url')
251-
results.next_page = json_list.get('next_page')
252-
results.results_per_page = json_list.get('results_per_page')
253-
results.page = json_list.get('page')
254-
results.completed_in = json_list.get('completed_in')
255-
results.query = json_list.get('query')
256-
257-
for obj in json_list['results']:
258-
results.append(cls.parse(api, obj))
236+
metadata = json['search_metadata']
237+
results = SearchResults(metadata.get('max_id'), metadata.get('since_id'))
238+
results.refresh_url = metadata.get('refresh_url')
239+
results.completed_in = metadata.get('completed_in')
240+
results.query = metadata.get('query')
241+
242+
for status in json['statuses']:
243+
results.append(Status.parse(api, status))
259244
return results
260245

261246

@@ -433,7 +418,7 @@ class ModelFactory(object):
433418
direct_message = DirectMessage
434419
friendship = Friendship
435420
saved_search = SavedSearch
436-
search_result = SearchResult
421+
search_results = SearchResults
437422
category = Category
438423
list = List
439424
relation = Relation

0 commit comments

Comments
 (0)