lastid = int(m.group(1)) except IOError: lastid = 12345 #fallback - download as many tweets as possible received = 1 alldata = [] page = 1 while page < 2 or (received > 20 and page < 20): url = 'http://api.twitter.com/1/direct_messages.json' head = ['Expect: '] data = [('count', 20), ('page', page)] #data = [('count', 200)] postdata = urllib.urlencode(data) url = url+'?'+postdata print url r, c = wcommon.oauth_req(url) if r.status > 200: print "Request failed: %d" % (r.status) sys.exit(1) print c jdata = json.loads(c) #print jdata alldata = alldata + jdata received = len(jdata) print str(received)+" messages" page += 1 page = 1 while page < 2 or (received > 20 and page < 20): url = 'http://api.twitter.com/1/direct_messages/sent.json' head = ['Expect: ']
import os import random import re import urllib import json import urllib2 import oauth2 as oauth import time import wcommon status = None if len(sys.argv) < 2 or sys.argv[1] == "-i": #interactive mode while not status: tweetid = long(raw_input("Tweet ID to RT: ")) elif len(sys.argv) > 1: tweetid = long(sys.argv[1]) else: sys.exit(1) url = "http://api.twitter.com/1/statuses/retweet/%d.xml" % (tweetid) data = [] postdata = urllib.urlencode(data) r, c = wcommon.oauth_req(url, http_method="POST", post_body=postdata) if r.status != 200: print "Retweeting did not succeed: Status %d" % (r.status) print c
exit(1) lastid = int(m.group(1)) except IOError: lastid = 12345 #fallback - download as many tweets as possible received = 1 alldata = [] page = 1 while page < 2 or (received > 20 and page < 20): url = 'http://api.twitter.com/1/direct_messages.xml' head = ['Expect: '] data = [('count', 10)] #data = [('count', 200)] postdata = urllib.urlencode(data) url = url+'?'+postdata print url r, c = wcommon.oauth_req(url) if r.status > 200: print "Request failed: %d" % (r.status) sys.exit(1) print c jdata = json.loads(c) #print jdata alldata = alldata + jdata received = len(jdata) print str(received)+" messages" page += 1 writelog(alldata)
# image = [imagefile] import sys import os import random import re import urllib import json import urllib2 import oauth2 as oauth import time import wcommon status = None if len(sys.argv) < 2 or sys.argv[1] == "-i": #interactive mode while not status: tweetid = long(raw_input("Tweet ID to RT: ")) elif len(sys.argv) > 1: tweetid = long(sys.argv[1]) else: sys.exit(1) url = "http://api.twitter.com/1/statuses/retweet/%d.xml" % (tweetid) data = [] postdata = urllib.urlencode(data) r, c = wcommon.oauth_req(url, http_method="POST", post_body=postdata) if r.status != 200: print "Retweeting did not succeed: Status %d" % (r.status) print c