searchTwitter() -> search() #42
No reviewers
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#42
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
searchTwitter() in twython and twython3k is changed to twython() and corresponding changes in README.markdown is also done.twython module i have tested and not twython3k
I felt most lines were more than 80 characters , I am planning to fix them , for example:
def send():
raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
above will cross 80 characters so it will be replaced as
Hey there,
I'm cool with the 80 lines bit; I know it's a thing for some people, but I've never cared too much. Absolutely no objections on a patch though!
As for the renaming... can you do it in a way where there's still a
searchTwitter()function that just maps over to the new one? I'd rather not break the API significantly for anyone who does a basic upgrade; newer people can easily hit thesearch()method, and it'll be the de-facto one going forward.Actually, another side note - let's do the same convention with the search Generator (e.g,
.searchGen()).searchGen() :
I will make changes for that too.
I will take time to fix 80 spaces in a line as soon as possible.
Nice! Thanks again!
Ryan:
searchGen().Will make 80 character per line in next few days, In case if it
is ok merge it else let me know .*
*
*
Known Issues:
In original version:searchTwitterGen() doesn't yield more than 2 tweet.
*
*
*
In [39]: a = twitter.searchTwitterGen("python", page = '1')
In [40]: a.next()
Out[40]:
{u'created_at': u'Sun, 02 Oct 2011 09:34:06 +0000',
u'from_user': u'Berneiceh90',
u'from_user_id': 409090123,
u'from_user_id_str': u'409090123',
u'geo': None,
u'id': 120431351408242688L,
u'id_str': u'120431351408242688',
u'iso_language_code': u'en',
u'metadata': {u'result_type': u'recent'},
u'profile_image_url': u'
http://a1.twimg.com/profile_images/1521029311/LLKP-0420_normal.jpg',
u'source': u'<a href="http://twitterfeed.com"
rel="nofollow">twitterfeed</a>',
u'text': u"Monty Python? #Simpsons? Basically the rest of my day is going
to be spent thinking about the Rochdale game's theme. http://t.co/gnya6UPu",
u'to_user_id': None,
u'to_user_id_str': None}
In [41]: a.next()
Out[41]:
{u'created_at': u'Thu, 29 Sep 2011 12:26:30 +0000',
u'from_user': u'ITJobs_EU_NL',
u'from_user_id': 235785444,
u'from_user_id_str': u'235785444',
u'geo': None,
u'id': 119387575206166528L,
u'id_str': u'119387575206166528',
u'iso_language_code': u'en',
u'metadata': {u'result_type': u'recent'},
u'profile_image_url': u'
http://a2.twimg.com/profile_images/1251729204/nl_2_normal.png',
u'source': u'<a href="http://twitterfeed.com"
rel="nofollow">twitterfeed</a>',
u'text': u'#JB Trading Performance Analyst: Job Description : Are you
looking for a job where every day is different? Are y...
http://t.co/NEO1XaJx',
u'to_user_id': None,
u'to_user_id_str': None}
In [42]: a.next()
TypeError Traceback (most recent call last)
/home/kracekumar/ in ()
/usr/local/lib/python2.7/dist-packages/twython/twython.pyc in
searchTwitterGen(self, search_query, *_kwargs)
333 kwargs['page'] = 2
334 else:
--> 335 kwargs['page'] += 1
336
337 for tweet in self.searchTwitterGen(search_query,
*_kwargs):
TypeError: cannot concatenate 'str' and 'int' objects
I have fixed this issue in my code
if 'page' not in kwargs:
kwargs['page'] = '2'
else:
try:
kwargs['page'] = int(kwargs['page'])
kwargs['page'] += 1
kwargs['page'] = str(kwargs['page'])
except TypeError:
raise TwythonError("searchGen() exited because page takes str")
except e:
raise TwythonError("searchGen() failed with %s error code" %
e.code, e.code)After fixing this issue, I get StopIteration
In [8]: a = twitter.searchTwitterGen('python', page = '1')
In [9]: a.next()
Out[9]:
{u'created_at': u'Sun, 02 Oct 2011 09:34:06 +0000',
u'from_user': u'Berneiceh90',
u'from_user_id': 409090123,
u'from_user_id_str': u'409090123',
u'geo': None,
u'id': 120431351408242688L,
u'id_str': u'120431351408242688',
u'iso_language_code': u'en',
u'metadata': {u'result_type': u'recent'},
u'profile_image_url':
u'http://a1.twimg.com/profile_images/1521029311/LLKP-0420_normal.jpg',
u'source': u'<a href="http://twitterfeed.com"
rel="nofollow">twitterfeed</a>',
u'text': u"Monty Python? #Simpsons? Basically the rest of my day is
going to be spent thinking about the Rochdale game's theme.
http://t.co/gnya6UPu",
u'to_user_id': None,
u'to_user_id_str': None}
In [10]: a.next()
Out[10]:
{u'created_at': u'Thu, 29 Sep 2011 12:26:30 +0000',
u'from_user': u'ITJobs_EU_NL',
u'from_user_id': 235785444,
u'from_user_id_str': u'235785444',
u'geo': None,
u'id': 119387575206166528L,
u'id_str': u'119387575206166528',
u'iso_language_code': u'en',
u'metadata': {u'result_type': u'recent'},
u'profile_image_url':
u'http://a2.twimg.com/profile_images/1251729204/nl_2_normal.png',
u'source': u'<a href="http://twitterfeed.com"
rel="nofollow">twitterfeed</a>',
u'text': u'#JB Trading Performance Analyst: Job Description : Are you
looking for a job where every day is different? Are y...
http://t.co/NEO1XaJx',
u'to_user_id': None,
u'to_user_id_str': None}
In [11]: a.next()
StopIteration Traceback (most recent call last)
/home/kracekumar/codes/python/twython/twython/ in ()
StopIteration:
So generator creates a list of tweets in our case it should yield
continuously 15 tweets from current page and once it exceeds 15 tweet
it should pull tweets from next page, correct me if I am wrong .
Hmmm, alright, I'm gonna go ahead and merge these now, I think they're alright. Thanks for the patch to the Search Generator method, surprised that nobody ever caught that one before...
Being that there's now default
searchTwitter/searchTwitterGenmethods to act as patches for older code, I feel better about moving this into a new release, as I've gotta do the same for the 3k branch anyway. Will most likely do that later tonight (it's 5AM here).Thanks again!
Its my pleasure and I have done it for twython3k too. . .
Ah, I just mirrored your changes over to the 3k build, no worries! It's all uber useful.
Now you can sleep happily :)