Skip to content

Instantly share code, notes, and snippets.

@kivantium
Created January 10, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kivantium/092da4fd5c01a6855e1a490e73c274fe to your computer and use it in GitHub Desktop.
Save kivantium/092da4fd5c01a6855e1a490e73c274fe to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#-*- coding: utf-8 -*-
from requests_oauthlib import OAuth1Session
import json
import HTMLParser
CK = 'XXXXXXXXXXXXXXXXXXXXXX' # Consumer Key
CS = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # Consumer Secret
AT = 'XXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # Access Token
AS = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # Accesss Token Secret
url = "https://api.twitter.com/1.1/statuses/user_timeline.json"
params = {"screen_name": "realDonaldTrump",
"count": 5,
"exclude_replies": "true",
"include_rts": "true"
}
twitter = OAuth1Session(CK, CS, AT, AS)
req = twitter.get(url, params = params)
html_parser = HTMLParser.HTMLParser()
if req.status_code == 200:
timeline = json.loads(req.text)
for tweet in timeline:
if not ('retweeted_status' in tweet):
print html_parser.unescape(tweet["text"]).encode('utf-8')
maxid = tweet["id"]
else:
print ("Error: %d" % req.status_code)
for i in range(20):
print '-------------------'
params = {"screen_name": "realDonaldTrump",
"count": 200,
"exclude_replies": "true",
"include_rts": "true",
"max_id": maxid - 1
}
req = twitter.get(url, params = params)
if req.status_code == 200:
timeline = json.loads(req.text)
for tweet in timeline:
if not ('retweeted_status' in tweet):
print html_parser.unescape(tweet["text"]).encode('utf-8')
maxid = tweet["id"]
else:
print ("Error: %d" % req.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment