-
Notifications
You must be signed in to change notification settings - Fork 3
/
twitter.py
36 lines (31 loc) · 1.13 KB
/
twitter.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
import tweepy
import os
from dotenv import load_dotenv
from time import sleep
load_dotenv() #Check Environment Variables in .env file
twitter_api= os.getenv('TWITTER_API')
twitter_secret= os.getenv('TWITTER_SECRET')
access_token= os.getenv('ACCESS_TOKEN')
access_secret=os.getenv('ACCESS_SECRET')
auth = tweepy.OAuthHandler(twitter_api, twitter_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth,
wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
def tweet(tokens, amount, settings, chain):
amount=int(amount)
amount=(f"{amount:,}")
line1="🚨 %s $MIM are available to be minted on #%s using $%s as collateral! 🚨" %(amount,settings[chain]['message_name'], tokens)
line2="💸 https://abracadabra.money/stand 💸"
message='\n \n'.join([line1, line2])
if len(message) < 280:
try:
api.update_status(message)
print("tweet sent!")
except tweepy.TweepError as e:
print(e.message[0]['code'])
except:
print("error sending tweet")
else:
print("tweet too long")
sleep(5)