-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweet_a_python.py
More file actions
69 lines (59 loc) · 2.24 KB
/
tweet_a_python.py
File metadata and controls
69 lines (59 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''
Created on Apr 4, 2014
@author: bonino
Copyright (c) 2014 Dario Bonino
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License
'''
import twitter, tts, urllib
def getTweets():
tweets = {}
# get access to apis
api = twitter.Api(consumer_key='wIDHvofdfV2QO94s1bjebQ',
consumer_secret='nO0q0Ko8EBQ6Lb8FNLwEsT3r2QLkjWsO02dr9uegU',
access_token_key='2408639030-691GXH8B4aQt2JgXN05uSkWAJyywmds6OeLCaI4',
access_token_secret='I7lxOY8wSBf0bKlWKJ5UlI3tVRoSaYUeiUseRLo9VBoky')
#get the user followers
users = api.GetFollowers()
#iterate over followers
for user in users:
#prepare an array of statuses for each follower
tweets[user.name] = []
i=1
#fill statuses
for status in api.GetUserTimeline(user.id):
tweets[user.name].append(status.text)
i+=1
if(i>2):
break
return tweets
def sayTweets(tweets = None):
'''Says tweets
Args:
tweets: the dictionary containing the tweets to read, keys represent the follower name, values are arrays of statuses
'''
if(tweets!=None):
#iterate over the dictionary keys
for key in tweets.keys():
#say the tweet author at first
tts.say('Tweet from %s'%key, 'en')
#iterate over tweets
for tweet in tweets[key]:
#encode the tweet text to be suitable for urls
tweet_text = urllib.urlencode({'text':tweet})
#cut-off "text:"
tweet_text = tweet_text[5:]
#read the status text
tts.say(tweet_text,'it')
if __name__ == '__main__':
#fetch tweets
tweets = getTweets()
#read tweets
sayTweets(tweets)