AnotherIndian commited on
Commit
01d832f
·
verified ·
1 Parent(s): 31012b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -32
app.py CHANGED
@@ -1,47 +1,26 @@
1
- import tweepy # Import the tweepy library to interact with Twitter API
2
- import openai # Import OpenAI API for language generation
3
- import time # Import time library to control tweet timing
 
4
 
5
- # Authentication for Twitter API
6
  def authenticate_twitter():
7
  auth = tweepy.OAuth1UserHandler(
8
- consumer_key='RGo5d1VySEtOd2VXX2p3MWEzWVU6MTpjaQ',
9
- consumer_secret='6yww6Q1YzERRPc4ypEXcTcK1J3ET_rKK7i88z9KDKiNoA7PpuC',
10
- access_token='1862985406393823232-gnHrZgwXsU3Y4822LfxyXp3ZMnDDNj',
11
- access_token_secret='lR6rNMOI6UtVmqtS6Nsa5lXR7k9f67qQ5FF6nOChdhjdU'
12
  )
13
  api = tweepy.API(auth)
14
  return api
15
 
16
  # Authentication for OpenAI API
17
  def authenticate_openai():
18
- openai.api_key = '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'
19
 
20
  # Function to generate a tweet using GPT-3
21
  def generate_tweet():
22
  response = openai.Completion.create(
23
- engine="text-davinci-003", # You can choose the model to use
24
- prompt="Create a tweet in the style of a humorous AI agent, keeping it casual and engaging.",
25
- max_tokens=50
26
- )
27
- tweet = response.choices[0].text.strip()
28
- return tweet
29
-
30
- # Function to send the tweet to Twitter
31
- def send_tweet(api, tweet):
32
- api.update_status(tweet) # Send the generated tweet
33
-
34
- # Main function to control the tweet posting loop
35
- def main():
36
- twitter_api = authenticate_twitter() # Get Twitter API instance
37
- authenticate_openai() # Authenticate OpenAI API
38
-
39
- while True:
40
- tweet = generate_tweet() # Generate a new tweet
41
- print(f"Tweeting: {tweet}")
42
- send_tweet(twitter_api, tweet) # Send the tweet to Twitter
43
- time.sleep(1800) # Wait for 30 minutes before posting the next tweet
44
 
45
- if __name__ == "__main__":
46
- main() # Start the program
47
 
 
1
+ import tweepy
2
+ import openai
3
+ import time
4
+ import os
5
 
6
+ # Authentication for Twitter API (using environment variables for security)
7
  def authenticate_twitter():
8
  auth = tweepy.OAuth1UserHandler(
9
+ consumer_key=os.getenv('TWITTER_API_KEY'),
10
+ consumer_secret=os.getenv('TWITTER_API_SECRET_KEY'),
11
+ access_token=os.getenv('TWITTER_ACCESS_TOKEN'),
12
+ access_token_secret=os.getenv('TWITTER_ACCESS_TOKEN_SECRET')
13
  )
14
  api = tweepy.API(auth)
15
  return api
16
 
17
  # Authentication for OpenAI API
18
  def authenticate_openai():
19
+ openai.api_key = os.getenv('OPENAI_API_KEY')
20
 
21
  # Function to generate a tweet using GPT-3
22
  def generate_tweet():
23
  response = openai.Completion.create(
24
+ engine="text-davinci-003", # Choose the model to u
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
 
 
26