Modified:
trunk/CHANGES.txt
trunk/README.txt
trunk/pyTwerp/twerp.py
Log:
10 Apr 2009 - bear
Removed all references to --since given that the Twitter folks
saw to removing the lovely by date parameter
Replaced it with since_id so that users of pyTwerp who make repeated
calls and expect only the new stuff to come across can continue to be
happy and all that.
Updated copyright info
Modified: trunk/CHANGES.txt
==============================================================================
--- trunk/CHANGES.txt (original)
+++ trunk/CHANGES.txt Fri Apr 10 14:52:49 2009
@@ -1,3 +1,14 @@
+10 Apr 2009 - bear
+
+ Removed all references to --since given that the Twitter folks
+ saw to removing the lovely by date parameter
+
+ Replaced it with since_id so that users of pyTwerp who make repeated
+ calls and expect only the new stuff to come across can continue to be
+ happy and all that.
+
+ Updated copyright info
+
15 Jul 2008 - bear
Updated copyright info and other minor updates.
Modified: trunk/README.txt
==============================================================================
--- trunk/README.txt (original)
+++ trunk/README.txt Fri Apr 10 14:52:49 2009
@@ -32,7 +32,6 @@
-T --template <text> Template string. This string is used to
format the data received from Twitter.
Details on the format can be found below.
- -s --since <date> Date used by Twerp when pulling data from
Twitter.
-d --direct <message> Send a direct message.
-t --timeline Twerp will ouput your timeline.
-f --friends Twerp will output your friend's timeline.
@@ -45,7 +44,7 @@
twerp -frp
twerp status message to post
twerp -d decklin direct message to decklin
- twerp -f --since "Wed, 01 Aug 2007 05:39:42 GMT"
+ twerp -f
Template Format
Modified: trunk/pyTwerp/twerp.py
==============================================================================
--- trunk/pyTwerp/twerp.py (original)
+++ trunk/pyTwerp/twerp.py Fri Apr 10 14:52:49 2009
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-# Copyright (c) 2007,2008 Mike Taylor and Decklin Foster
+# Copyright (c) 2007,2008,2009 Mike Taylor and Decklin Foster
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,9 +31,6 @@
twerp -t user Pull recent entires in a user's timeline
twerp -p Pull the recent public timeline
- All timeline requests can make use of the optional -s/--since parameter
- to limit how far back to pull.
-
Requires:
setuptools http://cheeseshop.python.org/pypi/setuptools
simplejson http://cheeseshop.python.org/pypi/simplejson
@@ -68,13 +65,16 @@
raise TwerpHTTPError('server returned status %d' % code)
def fetch(url, auth=None, post=None, mod=None):
- request = urllib2.Request(url)
+ if mod:
+ since_param = '?since_id=%s' % mod
+ else:
+ since_param = ''
+
+ request = urllib2.Request('%s%s' % (url, since_param))
request.add_header('User-Agent', USERAGENT)
if auth:
request.add_header('Authorization', auth)
- if mod:
- request.add_header('If-Modified-Since', mod)
if post:
post.update({'source': 'pytwerp'})
request.add_data(urllib.urlencode(post))
@@ -127,21 +127,21 @@
return result
-def getPublic(since=None):
+def getPublic(since_id=None):
url = 'http://twitter.com/statuses/public_timeline.json'
- return fetch(url, mod=since)
+ return fetch(url, mod=since_id)
-def getUser(auth, user, since=None):
+def getUser(auth, user, since_id=None):
url = 'http://twitter.com/statuses/user_timeline/%s.json' % user
- return fetch(url, auth, mod=since)
+ return fetch(url, auth, mod=since_id)
-def getFriends(auth, user, since=None):
+def getFriends(auth, user, since_id=None):
url = 'http://twitter.com/statuses/friends_timeline/%s.json' % user
- return fetch(url, auth, mod=since)
+ return fetch(url, auth, mod=since_id)
def getReplies(auth, since=None):
url = 'http://twitter.com/statuses/replies.json'
- return fetch(url, auth, mod=since)
+ return fetch(url, auth, mod=since_id)
def postStatus(auth, msg):
url = 'http://twitter.com/statuses/update.json'
@@ -162,6 +162,7 @@
raise TwerpDataError(e.args[0])
def showTimeline(fp, template, sanitize=False):
+ result = None
try:
data = simplejson.load(fp)
data.reverse()
@@ -172,9 +173,13 @@
text = text.replace('\n', ' ')
print text.encode(getpreferredencoding(), 'replace')
+
+ result = entry['id']
except (AttributeError, ValueError), e:
raise TwerpDataError(e.args[0])
+ return result
+
def checkOptions():
config = os.path.expanduser(os.path.join('~', '.twerprc'))
op = optparse.OptionParser(version='twerp %s' % VERSION)
@@ -186,7 +191,7 @@
op.add_option('-U', '--username', dest='username', default=None)
op.add_option('-P', '--password', dest='password', default=None)
op.add_option('-T', '--template', dest='template', default=None)
- op.add_option('-s', '--since', dest='since', default=None)
+ op.add_option('-s', '--since', dest='since_id', default=None)
op.add_option('-d', '--direct', dest='direct', default=None)
op.add_option('-t', '--timeline', dest='timeline', default=None)
op.add_option('-f', '--friends', dest='friends', default=False,
action='store_true')
@@ -199,7 +204,8 @@
cp = ConfigParser.RawConfigParser()
cp.add_section('account')
cp.add_section('display')
- cp.add_section('checked')
+ cp.add_section('checked') # deprecated since Twitter decided to screw
folks who know how to make HTTP calls
+ cp.add_section('last_id')
cp.read([options.confpath])
try:
@@ -226,7 +232,7 @@
return options, cp
-def saveConfig(options, cp, checked):
+def saveConfig(options, cp, last_id):
if not cp.has_option('account', 'username'):
cp.set('account', 'username', options.username)
if not cp.has_option('account', 'password'):
@@ -235,8 +241,8 @@
cp.set('display', 'verbose', options.verbose)
if not cp.has_option('display', 'template'):
cp.set('display', 'template', options.template)
- for k, v in checked.items():
- cp.set('checked', k, v)
+ for k, v in last_id.items():
+ cp.set('last_id', k, v)
cp.write(file(options.confpath, 'w'))
@@ -251,13 +257,12 @@
digest = base64.encodestring('%s:%s' % (options.username,
options.password))
auth = 'Basic %s' % digest[:-1]
- checked = dict(cp.items('checked'))
+ last_id = dict(cp.items('last_id'))
def doTimeline(t, func, **kwargs):
- since = options.since or checked.get(t)
- response = func(since=since, **kwargs)
- checked[t] = response.info().getheader('Date')
- showTimeline(response, options.template, options.sanitize)
+ since_id = options.since_id or last_id.get(t)
+ response = func(since_id=since_id, **kwargs)
+ last_id[t] = showTimeline(response, options.template,
options.sanitize)
def doMessage(m, func, **kwargs):
if not m:
@@ -288,12 +293,12 @@
doMessage(options.msg, postStatus, auth=auth)
if options.save_conf:
- saveConfig(options, cp, checked)
+ saveConfig(options, cp, last_id)
except KeyboardInterrupt:
sys.exit(130)
except TwerpNoChanges:
if options.verbose: print 'No changes since last run.'
- saveConfig(options, cp, checked)
+ saveConfig(options, cp, last_id)
sys.exit(1)
except TwerpDataError, e:
print >>sys.stderr, 'Problem reading data: %s' % e.args[0]