Search results meta data?

58 views
Skip to first unread message

JeffRo

unread,
Jan 21, 2010, 8:15:41 PM1/21/10
to tweepy
I noticed the search api returns a list of the search results, but no
meta data -- max_id, since_id, results_per_page, etc. I'd like to
return the full complex object from search -- the metadata plus a
results list associated with the object.

I began by modifying the parse_search_results(obj, api) method in
parsers.py to the following:

def parse_search_results(obj, api):
searchresults = api.model_factor.search_results()
setattr(searchresults, 'max_id', obj['max_id'])
setattr(searchresults, 'since_id', obj['since_id'])
results = obj['results']
result_objects = []
for item in results:
result_objects.append(parse_search_result(item, api)
setattr(searchresults, 'results', result_objects)
return searchresults

In a script, I call the search:
searchresults = tweepy.api.search
(q=keywordphrase,lang='en',rpp=100,since_id=since_id)
print searchresults.max_id

Which yields an error:
AttributeError: 'list' object has no attribute 'max_id'

I'm still wet behind the ears in Python, so I may be doing something
completely stupid here. I made the changes in Tweepy source, then ran
this. Am I on the right track, or am I missing something significant?

thx,
j

Josh Roesslein

unread,
Jan 21, 2010, 9:40:27 PM1/21/10
to twe...@googlegroups.com
Hey Jeff,

You can not set attributes directly on a list. I will fix this issue
in the future, but for now you can try this fix.
Define this class in models.py:

class SearchResults(list):
pass

And add this to the ModelFactory class:

search_results = SearchResults

That should do the trick. Let me know if you run into any more issues.

Josh

Pascal Jürgens

unread,
Jan 22, 2010, 10:18:15 AM1/22/10
to twe...@googlegroups.com
Hi Jeff,

haven't looked at your code, but did you install the modified tweepy version?
Before python uses it, you need to install it by running python setup.py install so that it gets packaged in an egg and placed in the right directory.
Unless you do this, running "import tweepy" will import the old version.

Cheers,
Pascal

Josh Roesslein

unread,
Jan 28, 2010, 9:34:18 PM1/28/10
to twe...@googlegroups.com
Tweepy now returns ResultSet objects instead of lists.
The search() method now includes this "meta" data inside this
ResultSet object as attributes.

See this [1] commit for more details.

Josh

[1] http://github.com/joshthecoder/tweepy/commit/68c0f829361faecf35664df8744183d2cf68be6b

2010/1/22 Pascal Jürgens <pascal....@googlemail.com>:

Reply all
Reply to author
Forward
0 new messages