searchTwitter() -> search() #42

Merged
kracekumar merged 4 commits from master into master 2011-10-06 13:02:06 -07:00
kracekumar commented 2011-10-03 11:14:52 -07:00 (Migrated from github.com)

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

        raise Exception("Twython requires the simplejson library (or Python \
                                     2.6) to work. http://www.undefined.org/python/")
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 ``` raise Exception("Twython requires the simplejson library (or Python \ 2.6) to work. http://www.undefined.org/python/") ```
ryanmcgrath commented 2011-10-03 15:07:21 -07:00 (Migrated from github.com)

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 the search() method, and it'll be the de-facto one going forward.

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 the `search()` method, and it'll be the de-facto one going forward.
ryanmcgrath commented 2011-10-03 18:29:03 -07:00 (Migrated from github.com)

Actually, another side note - let's do the same convention with the search Generator (e.g, .searchGen()).

Actually, another side note - let's do the same convention with the search Generator (e.g, `.searchGen()`).
kracekumar commented 2011-10-03 20:17:46 -07:00 (Migrated from github.com)

can you do it in a way where there's still a searchTwitter() function
that just maps over to the new one?

   Yes I am making a fallback for it.

searchGen() :
I will make changes for that too.

I will take time to fix 80 spaces in a line as soon as possible.

> can you do it in a way where there's still a `searchTwitter()` function > that just maps over to the new one? ``` Yes I am making a fallback for it. ``` searchGen() : I will make changes for that too. I will take time to fix 80 spaces in a line as soon as possible.
ryanmcgrath commented 2011-10-03 23:37:02 -07:00 (Migrated from github.com)

Nice! Thanks again!

Nice! Thanks again!
kracekumar commented 2011-10-04 19:36:17 -07:00 (Migrated from github.com)

Ryan:

  • I have changed searchTwitter() -> search() & searchTwitterGen() ->
    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 .

Ryan: - I have changed searchTwitter() -> search() & searchTwitterGen() -> 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'&lt;a href=&quot;http://twitterfeed.com&quot; rel=&quot;nofollow&quot;&gt;twitterfeed&lt;/a&gt;', 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'&lt;a href=&quot;http://twitterfeed.com&quot; rel=&quot;nofollow&quot;&gt;twitterfeed&lt;/a&gt;', 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/<ipython console> in <module>() /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'&lt;a href=&quot;http://twitterfeed.com&quot; rel=&quot;nofollow&quot;&gt;twitterfeed&lt;/a&gt;', 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'&lt;a href=&quot;http://twitterfeed.com&quot; rel=&quot;nofollow&quot;&gt;twitterfeed&lt;/a&gt;', 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/<ipython console> in <module>() 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 . *
ryanmcgrath commented 2011-10-06 13:02:14 -07:00 (Migrated from github.com)

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/searchTwitterGen methods 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!

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`/`searchTwitterGen` methods 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!
kracekumar commented 2011-10-06 13:29:39 -07:00 (Migrated from github.com)

Its my pleasure and I have done it for twython3k too. . .

Its my pleasure and I have done it for twython3k too. . .
ryanmcgrath commented 2011-10-06 13:43:56 -07:00 (Migrated from github.com)

Ah, I just mirrored your changes over to the 3k build, no worries! It's all uber useful.

Ah, I just mirrored your changes over to the 3k build, no worries! It's all uber useful.
kracekumar commented 2011-10-06 13:48:24 -07:00 (Migrated from github.com)

Now you can sleep happily :)

Now you can sleep happily :)
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#42
No description provided.