-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.py
29 lines (26 loc) · 870 Bytes
/
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
import os
import tweepy
from dotenv import load_dotenv
load_dotenv()
# Global def so that it does not create new client for each platform
CONSUMER_KEY = os.getenv("CONSUMER_KEY")
CONSUMER_SECRET = os.getenv("CONSUMER_SECRET")
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
ACCESS_TOKEN_SECRET = os.getenv("ACCESS_TOKEN_SECRET")
BEARER_TOKEN = os.getenv("BEARER_TOKEN")
TESTING_MODE = os.getenv("TESTING_MODE")
client = tweepy.Client(
consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
access_token=ACCESS_TOKEN,
access_token_secret=ACCESS_TOKEN_SECRET,
bearer_token=BEARER_TOKEN
)
class Twitter:
def __init__(self):
self.client = client
def update_status(self, tweet):
if TESTING_MODE.lower() == 'false':
self.client.create_tweet(text=tweet)
else:
print(f"Testing mode on, not posting.")