From d9fcd3a264edf62ec5b5a11c67f9d7ec3a740294 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:37:43 +0800 Subject: [PATCH 1/9] Fixing setup.py script to use valid `setuptools` format. This will fix the broken pip / easy_install issues on many platforms (like most linux distros). --- setup.py | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 7a436b2..feb0be6 100644 --- a/setup.py +++ b/setup.py @@ -1,46 +1,42 @@ #!/usr/bin/python import sys, os +from setuptools import setup +from setuptools import find_packages + __author__ = 'Ryan McGrath ' __version__ = '1.2' -# Distutils version -METADATA = dict( - name = "twython", + +setup( + + # Basic package information. + name = 'twython', version = __version__, - py_modules = ['setup', 'twython/__init__', 'twython/core', 'twython/twyauth', 'twython/streaming', 'twython/oauth'], + packages = find_packages(), + + # Packaging options. + include_package_data = True, + + # Package dependencies. + install_requires = ['setuptools', 'simplejson'], + + # Metadata for PyPI. author = 'Ryan McGrath', author_email = 'ryan@venodesigns.net', - description = 'An easy (and up to date) way to access Twitter data with Python.', - long_description = open("README.markdown").read(), license = 'MIT License', url = 'http://github.com/ryanmcgrath/twython/tree/master', keywords = 'twitter search api tweet twython', -) - -# Setuptools version -SETUPTOOLS_METADATA = dict( - install_requires = ['setuptools', 'simplejson'], - include_package_data = True, + description = 'An easy (and up to date) way to access Twitter data with Python.', + long_description = open('README.markdown').read(), classifiers = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Communications :: Chat', - 'Topic :: Internet', + 'Topic :: Internet' ] + ) - -def Main(): - try: - import setuptools - METADATA.update(SETUPTOOLS_METADATA) - setuptools.setup(**METADATA) - except ImportError: - import distutils.core - distutils.core.setup(**METADATA) - -if __name__ == '__main__': - Main() From 9f7e1fa121be6f027181725fc57f737590c9edc5 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:40:10 +0800 Subject: [PATCH 2/9] Adding a proper MANIFEST.in to the project. This file will instruct setuptools to package *all* important distribution packages when the code gets uploaded to PyPI. --- MANIFEST.in | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..0d9cce8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include LICENSE README.markdown +recursive-include examples * +recursive-exclude examples *.pyc From fb6d549eedd963ffbba22b55d1af7da56777ee00 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:45:51 +0800 Subject: [PATCH 3/9] Adding blocking for vim swap files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 996a1e1..0b15049 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build dist twython.egg-info +*.swp From d5b2c98fb880961d382118eaf9f1c4d837c444ce Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:47:59 +0800 Subject: [PATCH 4/9] PEP-8'ing imports. Also removing useless docstring. Only the *first* docstring defined in a source file will be associated with that module's __doc__ string. So I'm removing the second one that was there as it is unnecessary. --- twython/core.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/twython/core.py b/twython/core.py index d380fbd..921e461 100644 --- a/twython/core.py +++ b/twython/core.py @@ -10,15 +10,20 @@ Questions, comments? ryan@venodesigns.net """ -import httplib, urllib, urllib2, mimetypes, mimetools + +import httplib +import urllib +import urllib2 +import mimetypes +import mimetools from urlparse import urlparse from urllib2 import HTTPError + __author__ = "Ryan McGrath " __version__ = "1.1" -"""Twython - Easy Twitter utilities in Python""" try: import simplejson From a8ae71fd75c0025f817064cefe7d6bcab1f4204f Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:54:47 +0800 Subject: [PATCH 5/9] Adding a bit more PEP-8. --- twython/core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/twython/core.py b/twython/core.py index 921e461..496142d 100644 --- a/twython/core.py +++ b/twython/core.py @@ -36,6 +36,7 @@ except ImportError: except: raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/") + class TwythonError(Exception): def __init__(self, msg, error_code=None): self.msg = msg @@ -44,18 +45,21 @@ class TwythonError(Exception): def __str__(self): return repr(self.msg) + class APILimit(TwythonError): def __init__(self, msg): self.msg = msg def __str__(self): return repr(self.msg) + class AuthError(TwythonError): def __init__(self, msg): self.msg = msg def __str__(self): return repr(self.msg) + class setup: def __init__(self, username = None, password = None, headers = None, proxy = None, version = 1): """setup(username = None, password = None, proxy = None, headers = None) From c2f87f736cad6e1e5248f0f1fbffc91cf78d92d2 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 16:59:34 +0800 Subject: [PATCH 6/9] Adding some more PEP-8. All lines should be at most 79 characters in length. --- twython/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/twython/core.py b/twython/core.py index 496142d..61cb00e 100644 --- a/twython/core.py +++ b/twython/core.py @@ -61,7 +61,9 @@ class AuthError(TwythonError): class setup: - def __init__(self, username = None, password = None, headers = None, proxy = None, version = 1): + + def __init__(self, username=None, password=None, headers=None, proxy=None, + version=1): """setup(username = None, password = None, proxy = None, headers = None) Instantiates an instance of Twython. Takes optional parameters for authentication and such (see below). From 3580ee22b5b30f67a5621b1e9333640f64f54d78 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 17 Aug 2010 17:09:52 +0800 Subject: [PATCH 7/9] Don't need to include `setuptools`, heh. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index feb0be6..800c67e 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( include_package_data = True, # Package dependencies. - install_requires = ['setuptools', 'simplejson'], + install_requires = ['simplejson'], # Metadata for PyPI. author = 'Ryan McGrath', From e9aaaa7c39dad0306fec9e83cb377975f5c2d4d5 Mon Sep 17 00:00:00 2001 From: Juan Jose Conti Date: Tue, 24 Aug 2010 09:52:09 +0800 Subject: [PATCH 8/9] Added a method to return a generator based in Twitter search API. --- twython/core.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/twython/core.py b/twython/core.py index 61cb00e..c41ef12 100644 --- a/twython/core.py +++ b/twython/core.py @@ -1371,6 +1371,51 @@ class setup: except HTTPError, e: raise TwythonError("getSearchTimeline() failed with a %s error code." % `e.code`, e.code) + def searchTwitterGen(self, search_query, **kwargs): + """searchTwitterGen(search_query, **kwargs) + + Returns a generator of tweets that match a specified query. + + Parameters: + callback - Optional. Only available for JSON format. If supplied, the response will use the JSONP format with a callback of the given name. + lang - Optional. Restricts tweets to the given language, given by an ISO 639-1 code. + locale - Optional. Language of the query you're sending (only ja is currently effective). Intended for language-specific clients; default should work in most cases. + rpp - Optional. The number of tweets to return per page, up to a max of 100. + page - Optional. The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page. Note: there are pagination limits.) + since_id - Optional. Returns tweets with status ids greater than the given id. + geocode - Optional. Returns tweets by users located within a given radius of the given latitude/longitude, where the user's location is taken from their Twitter profile. The parameter value is specified by "latitide,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly. + show_user - Optional. When true, prepends ":" to the beginning of the tweet. This is useful for readers that do not display Atom's author field. The default is false. + + Usage Notes: + Queries are limited 140 URL encoded characters. + Some users may be absent from search results. + The since_id parameter will be removed from the next_page element as it is not supported for pagination. If since_id is removed a warning will be added to alert you. + This method will return an HTTP 404 error if since_id is used and is too old to be in the search index. + + Applications must have a meaningful and unique User Agent when using this method. + An HTTP Referrer is expected but not required. Search traffic that does not include a User Agent will be rate limited to fewer API calls per hour than + applications including a User Agent string. You can set your custom UA headers by passing it as a respective argument to the setup() method. + """ + searchURL = self.constructApiURL("http://search.twitter.com/search.json", kwargs) + "&" + urllib.urlencode({"q": self.unicode2utf8(search_query)}) + try: + data = simplejson.load(self.opener.open(searchURL)) + except HTTPError, e: + raise TwythonError("searchTwitterGen() failed with a %s error code." % `e.code`, e.code) + + if not data['results']: + raise StopIteration + + for tweet in data['results']: + yield tweet + + if 'page' not in kwargs: + kwargs['page'] = 2 + else: + kwargs['page'] += 1 + + for tweet in self.searchTwitterGen(search_query, **kwargs): + yield tweet + def getCurrentTrends(self, excludeHashTags = False, version = None): """getCurrentTrends(excludeHashTags = False, version = None) From 2a5d66880134a5dd20484cad30b39f146c42efaa Mon Sep 17 00:00:00 2001 From: Mark Liu Date: Sat, 11 Sep 2010 07:12:23 +0800 Subject: [PATCH 9/9] Added a missing parameter to addListMember --- twython/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twython/core.py b/twython/core.py index c41ef12..41bcff5 100644 --- a/twython/core.py +++ b/twython/core.py @@ -1701,20 +1701,20 @@ class setup: raise AuthError("It seems the list you're trying to access is private/protected, and you don't have access. Are you authenticated and allowed?") raise TwythonError("getSpecificList() failed with a %d error code." % e.code, e.code) - def addListMember(self, list_id, version = None): + def addListMember(self, list_id, id, version = None): """ addListMember(self, list_id, id, version) Adds a new Member (the passed in id) to the specified list. Parameters: list_id - Required. The slug of the list to add the new member to. - id - Required. The ID of the user that's being added to the list. + id - Required. The ID or slug of the user that's being added to the list. version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc. """ version = version or self.apiVersion if self.authenticated is True: try: - return simplejson.load(self.opener.open("http://api.twitter.com/%d/%s/%s/members.json" % (version, self.username, list_id), "id=%s" % `id`)) + return simplejson.load(self.opener.open("http://api.twitter.com/%d/%s/%s/members.json" % (version, self.username, list_id), "id=%s" % (id))) except HTTPError, e: raise TwythonError("addListMember() failed with a %d error code." % e.code, e.code) else: