This repository has been archived by the owner on Feb 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (48 loc) · 1.81 KB
/
app.py
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
from Meh import Config, Option, ExceptionInConfigError
from facepy import GraphAPI
import tweepy
from time import sleep
CONFIG_PATH = "config.cfg"
config = Config()
config += Option("twitter_accounts", ("robot0nfire", "team_items"),
validator=lambda x: type(x) in (tuple, list), comment="Twitter accounts")
config += Option("twitter_consumer_token", "", comment="Twitter consumer token")
config += Option("twitter_consumer_secret", "", comment="Twitter consumer secret")
config += Option("twitter_access_token", "", comment="Twitter access token")
config += Option("twitter_access_token_secret", "", comment="Twitter access token secret")
config += Option("poll_rate", 60, comment="Twitter access token secret")
config += Option("facebook_oauth", "", comment="Facebook Graph API token")
try:
config = config.load(CONFIG_PATH)
except (IOError, ExceptionInConfigError):
config.dump(CONFIG_PATH)
config = config.load(CONFIG_PATH)
auth = tweepy.OAuthHandler(config.twitter_consumer_token, config.twitter_consumer_secret)
auth.set_access_token(config.twitter_access_token, config.twitter_access_token_secret)
api = tweepy.API(auth)
twitter_users = []
for user in config.twitter_accounts:
twitter_users.append(api.get_user(user))
last_ids = {}
for user in twitter_users:
last_ids[user] = user.timeline()[0].id
try:
while True:
to_retweet = []
for user in twitter_users:
tweets_ = user.timeline(since_id=last_ids[user])
tweets = []
for tweet in tweets_:
if "#robot4you" in tweet.text or "#r4y" in tweet.text:
tweets.append(tweet)
if len(tweets) > 0:
print("New tweets by '%s'" % user.name)
last_ids[user] = tweets[0].id
for tweet in tweets:
print(tweet.text)
to_retweet.append(tweet.id)
for tweet_id in to_retweet:
api.retweet(tweet_id)
sleep(config.poll_rate)
except KeyboardInterrupt:
pass