-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (48 loc) · 1.75 KB
/
main.py
File metadata and controls
52 lines (48 loc) · 1.75 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 os
import tweepy
import datetime
import json
import requests
consumer_key = os.environ['TWITTER_API_KEY']
consumer_secret = os.environ['TWITTER_API_SECRET_KEY']
access_token = os.environ['TWITTER_ACCESS_TOKEN']
access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET']
#auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
#auth.set_access_token(access_token, access_token_secret)
#api = tweepy.API(auth)
#api.update_status(status='test')
#print("images tweeted")
with open('quotes.json', 'r') as f:
quotes = json.load(f)
# Load last tweeted quote index from a file
if os.path.exists('last_tweet_index.txt'):
with open('last_tweet_index.txt', 'r') as f:
tweet_index = int(f.read().strip())
else:
tweet_index = -1
print(f'index : {tweet_index}')
# Get the quote to tweet
quote = quotes[tweet_index]
# Compose the tweet text
tweet_text = f'"{quote["quote"]}" - {quote["character"]}'
#image_url = quote['image']
#filename = f"image.jpg"
#image = requests.get(image_url).content
#with open(filename, "wb") as f:
# f.write(image)
#media_upload = api.media_upload(filename)
#tweet_media_id = media_upload.media_id
#api.update_status(status=tweet_text, media_ids=[tweet_media_id])
#api.update_status(status=tweet_text)
client = tweepy.Client(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret)
# Replace the text with whatever you want to Tweet about
response = client.create_tweet(text=tweet_text)
print(f'Tweeted: {tweet_text}')
next_tweet_index = (tweet_index + 1)
if next_tweet_index not in range(0, 15):
next_tweet_index = 0
with open('last_tweet_index.txt', 'w') as f:
f.write(str(next_tweet_index))