From: mverdone Date: Mon, 7 Apr 2008 21:33:23 +0000 (+0000) Subject: First import X-Git-Tag: twitter-0.2~11 X-Git-Url: https://jfr.im/git/z_archive/twitter.git/commitdiff_plain/7364ea659298faff7a1c9fd180130c4b91239050 First import git-svn-id: http://svn.mike.verdone.ca/pyprojects/twitter/trunk@155 d723f978-dc38-0410-87ed-da353333cdcc --- 7364ea659298faff7a1c9fd180130c4b91239050 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..01bb954 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[egg_info] +tag_build = dev +tag_svn_revision = true diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..575ceff --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +from setuptools import setup, find_packages +import sys, os + +version = '0.1' + +setup(name='twitter', + version=version, + description="An API and command-line toolset for Twitter (twitter.com)", + long_description="""\ +""", + classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers + keywords='twitter', + author='Mike Verdone', + author_email='mike.verdone@gmail.com', + url='http://mike.verdone.ca/twitter/', + license='', + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=True, + install_requires=[ + # -*- Extra requirements: -*- + ], + entry_points=""" + # -*- Entry points: -*- + """, + ) diff --git a/twitter.egg-info/PKG-INFO b/twitter.egg-info/PKG-INFO new file mode 100644 index 0000000..3e6189b --- /dev/null +++ b/twitter.egg-info/PKG-INFO @@ -0,0 +1,11 @@ +Metadata-Version: 1.0 +Name: twitter +Version: 0.1dev +Summary: An API and command-line toolset for Twitter (twitter.com) +Home-page: http://mike.verdone.ca/twitter/ +Author: Mike Verdone +Author-email: mike.verdone@gmail.com +License: UNKNOWN +Description: UNKNOWN +Keywords: twitter +Platform: UNKNOWN diff --git a/twitter.egg-info/SOURCES.txt b/twitter.egg-info/SOURCES.txt new file mode 100644 index 0000000..c8c2309 --- /dev/null +++ b/twitter.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +setup.cfg +setup.py +twitter/__init__.py +twitter.egg-info/PKG-INFO +twitter.egg-info/SOURCES.txt +twitter.egg-info/dependency_links.txt +twitter.egg-info/entry_points.txt +twitter.egg-info/top_level.txt +twitter.egg-info/zip-safe diff --git a/twitter.egg-info/dependency_links.txt b/twitter.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/twitter.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/twitter.egg-info/entry_points.txt b/twitter.egg-info/entry_points.txt new file mode 100644 index 0000000..5d3e5f6 --- /dev/null +++ b/twitter.egg-info/entry_points.txt @@ -0,0 +1,3 @@ + + # -*- Entry points: -*- + \ No newline at end of file diff --git a/twitter.egg-info/paster_plugins.txt b/twitter.egg-info/paster_plugins.txt new file mode 100644 index 0000000..8e50835 --- /dev/null +++ b/twitter.egg-info/paster_plugins.txt @@ -0,0 +1 @@ +PasteScript diff --git a/twitter.egg-info/top_level.txt b/twitter.egg-info/top_level.txt new file mode 100644 index 0000000..37d1823 --- /dev/null +++ b/twitter.egg-info/top_level.txt @@ -0,0 +1 @@ +twitter diff --git a/twitter.egg-info/zip-safe b/twitter.egg-info/zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/twitter.egg-info/zip-safe @@ -0,0 +1 @@ + diff --git a/twitter/__init__.py b/twitter/__init__.py new file mode 100644 index 0000000..5c33def --- /dev/null +++ b/twitter/__init__.py @@ -0,0 +1,7 @@ +""" +The minimalist yet fully featured Twitter API and Python toolset. + +For building your own applications, look at the `Twitter` class. +""" + +from api import * diff --git a/twitter/api.py b/twitter/api.py new file mode 100644 index 0000000..21e18ee --- /dev/null +++ b/twitter/api.py @@ -0,0 +1,93 @@ + +from base64 import b64encode + +import httplib +import simplejson + +class TwitterCall(object): + def __init__(self, username=None, password=None, uri=""): + self.username = username + self.password = password + self.uri = uri + def __getattr__(self, k): + try: + return object.__getattr__(self, k) + except AttributeError: + return TwitterCall( + self.username, self.password, self.uri + "/" + k) + def __call__(self, **kwargs): + method = "GET" + if self.uri.endswith('new') or self.uri.endswith('update'): + method = "POST" + argStr = "" + if kwargs: + argStr = "?" + "&".join([ + "%s=%s" %(k, v) for k, v in kwargs.iteritems()]) + c = httplib.HTTPConnection("twitter.com") + try: + c.putrequest(method, "/%s.json%s" %(self.uri, argStr)) + if (self.username): + c.putheader("Authorization", "Basic " + + b64encode("%s:%s" %( + self.username, self.password))) + c.endheaders() + r = c.getresponse() + if (r.status == 304): + return [] + elif (r.status != 200): + raise Exception("Twitter sent status %i: %s" %( + r.status, r.read())) + return simplejson.loads(r.read()) + finally: + c.close() + +class Twitter(TwitterCall): + """ + The minimalist yet fully featured Twitter API class. + + Get RESTful data by accessing members of this class. The result + is decoded python objects (lists and dicts). + + The Twitter API is documented here: + http://groups.google.com/group/twitter-development-talk/web/api-documentation + + Examples:: + + twitter = Twitter("hello@foo.com", "password123") + + # Get the public timeline + twitter.statuses.public_timeline() + + # Get a particular friend's timeline + twitter.statuses.friends_timeline(id="billybob") + + # Also supported (but totally weird) + twitter.statuses.friends_timeline.billybob() + + # Send a direct message + twitter.direct_messages.new( + user="billybob", + text="I think yer swell!") + + Using the data returned:: + + Twitter API calls return decoded JSON. This is converted into + a bunch of Python lists, dicts, ints, and strings. For example, + + x = twitter.statuses.public_timeline() + + # The first 'tweet' in the timeline + x[0] + + # The screen name of the user who wrote the first 'tweet' + x[0]['user']['screen_name'] + + """ + def __init__(self, email=None, password=None): + """ + Create a new twitter API connector using the specified + credentials (email and password). + """ + TwitterCall.__init__(self, email, password) + +__all__ = ["Twitter"] diff --git a/twitter/cmdline.py b/twitter/cmdline.py new file mode 100644 index 0000000..af2a51d --- /dev/null +++ b/twitter/cmdline.py @@ -0,0 +1,7 @@ +""" +Twitter command line tool. + +""" + +def main(): + pass