-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitterbot.py
55 lines (43 loc) · 1.27 KB
/
twitterbot.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import openai, tweepy, random, config
# Twitter API credentials
api_key=config.twitter_api_key
api_key_secret =config.twitter_api_key_secret
access_token=config.access_token
access_token_secret=config.access_token_secret
#OpenAI API credentials
openai.api_key =config.open_ai_key
# Connecting to Twitter
auth = tweepy.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
print("Connected to Twitter")
# # Creating Tweets
prompts = [
{
"hashtag": "#softwaredeveloper",
"text": "I want to become a bettter developer"
},
]
# def __init__(self):
# error = 1
# while(error == 1):
# tweet = self.create_tweet()
# try:
# error = 0
# self.api.update_status(tweet)
# except:
# error = 1
def create_tweet():
chosen_prompt = random.choice(prompts)
text = chosen_prompt["text"]
hashtags = chosen_prompt["hashtag"]
response = openai.Completion.create(
engine="text-davinci-001",
prompt=text,
max_tokens=50,
)
tweet = response.choices[0].text
tweet = tweet + " " + hashtags + " " + "#ai #openai #gpt3"
return tweet
tweet = create_tweet()
api.update_status(tweet)