-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluminosity.py
More file actions
52 lines (41 loc) · 1.15 KB
/
luminosity.py
File metadata and controls
52 lines (41 loc) · 1.15 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
import json
import random
import time
import tweepy
import sys
from os import environ
CONSUMER_KEY = environ['CONSUMER_KEY']
CONSUMER_SECRET = environ['CONSUMER_SECRET']
ACCESS_KEY = environ['ACCESS_KEY']
ACCESS_SECRET = environ['ACCESS_SECRET']
def get_quotes():
with open('quotes.json') as f:
quotes_json = json.load(f)
return quotes_json['quotes']
def generate_quote():
quotes = get_quotes()
gen_quote = random.choice(quotes)
return gen_quote
def create_tweet():
quote = generate_quote()
tweet = """
{}
~{}
#motivation #power
""".format(quote['quote'], quote['author'])
return tweet
def tweet_quote():
interval = 60 * 60 * 12
#one tweet for every 12 hours
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_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()