forked from jethroodeyemi/quote-tweeting-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
49 lines (39 loc) · 1.12 KB
/
bot.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
import json
import random
import time
import sys
import tweepy
import credentials
consumer_key = credentials.API_KEY
consumer_secret_key = credentials.API_SECRET_KEY
access_token = credentials.ACCESS_TOKEN
access_token_secret = credentials.ACCESS_TOKEN_SECRET
def get_quotes():
with open('data.json') as f:
quotes_json = json.load(f)
return quotes_json['quotes']
def get_random_quote():
quotes = get_quotes()
random_quote = random.choice(quotes)
return random_quote
def create_tweet():
quote = get_random_quote()
tweet = """
{}
~{}
""".format(quote['quote'], quote['character'])
return tweet
def tweet_quote():
interval = 60 * 60 * 24
auth = tweepy.OAuthHandler(consumer_key, consumer_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# tweet = create_tweet()
# api.update_status(tweet)
while True:
print('getting a random quote...')
tweet = create_tweet()
api.update_status(tweet)
time.sleep(interval)
if __name__ == "__main__":
tweet_quote()