-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweeter.py
More file actions
43 lines (33 loc) · 1.45 KB
/
tweeter.py
File metadata and controls
43 lines (33 loc) · 1.45 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
import tweepy
import time
from scraper import tips_and_resources
def tweeting():
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
# Authenticate with Twitter API
auth = tweepy.OAuth1UserHandler(consumer_key, consumer_secret, access_token, access_token_secret)
api = tweepy.API(auth)
tweeted = set() # Create a set to store previously tweeted articles
for tweet in tweepy.Cursor(api.user_timeline).items():
tweeted.add(tweet.text.split("\n", 1)[0])
print(tweeted)
while True:
for item in tips_and_resources:
tweet_exists = False
# Check if the current tweet has already been posted
if item['title'].strip() in tweeted:
continue
if tweet_exists:
continue
if not tweet_exists: # If tweet hasn't been tweeted, tweet it
try:
api.update_status(item["title"] + "\n" + item["link"] + "\n#gamedev #indiegames #gamingnews #gamingindustry #gamebot" + " #" + item['title'].split(" ", 1)[0].lower())
time.sleep(20)
except tweepy.errors.TweepyException as e: # Exception handling
if e == 187:
print("Duplicate tweet.\n")
continue
else:
continue