Skip to content

Commit f0b295d

Browse files
committed
Merge pull request #32 from cjzhang/master
Update tumblrdottext to work with api v 1.1
2 parents b9ea313 + 42ec5a4 commit f0b295d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

botmily/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def getConfig():
2828
global tumblr_tumbling
2929
global wolframalpha_api_key
3030
global lastfm_api_key
31+
global oauth_token
32+
global oauth_secret
33+
global consumer_key
34+
global consumer_secret
3135
config = ConfigParser()
3236
config.read('config.ini')
3337
name = config.get('main', 'name')
@@ -41,6 +45,10 @@ def getConfig():
4145
tumblr_title = config.get('tumblr','post_titles')
4246
wolframalpha_api_key = config.get('wolframalpha', 'api_key')
4347
lastfm_api_key = config.get('lastfm', 'api_key')
48+
oauth_token = config.get('twitter', 'oauth_token')
49+
oauth_secret = config.get('twitter', 'oauth_secret')
50+
consumer_key = config.get('twitter', 'consumer_key')
51+
consumer_secret = config.get('twitter', 'consumer_secret')
4452
print("I will use the name: " + name)
4553
print("I will connect to the server: " + server)
4654
print("I will connect to the channels: " + ", ".join(channels))

plugins/tumblrdottext.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
from __future__ import unicode_literals
44

55
from twitter import Twitter
6+
from twitter import OAuth
7+
from botmily import config
68
import random
7-
#randomly return one of the last 50 tweets from https://twitter.com/TumblrTXT
9+
#randomly return one of the last 200 tweets from https://twitter.com/TumblrTXT
10+
#rate limit is 300 requests per 15 minutes
811
def tumblr(message_data, bot):
9-
t = Twitter(api_version=1)
10-
tweetno = random.randint(0,49)
11-
tweet = t.statuses.user_timeline.tumblrtxt(count=50)[tweetno]
12+
t = Twitter(api_version=1.1, auth=OAuth(config.oauth_token,
13+
config.oauth_secret, config.consumer_key, config.consumer_secret))
14+
tweetno = random.randint(0,199)
15+
tweet = t.statuses.user_timeline.tumblrtxt(count=200)[tweetno]
1216
return tweet['text']
1317

1418

0 commit comments

Comments
 (0)