BugZoid commited on
Commit
af4dae9
·
verified ·
1 Parent(s): bdcfb66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -56,8 +56,13 @@ def fetch_tweets(client, query, tweet_fields):
56
  wait=wait_exponential(multiplier=1, min=4, max=10),
57
  retry=lambda e: isinstance(e, tweepy.errors.TooManyRequests)
58
  )
59
- def post_tweet(api, text):
60
- return api.update_status(status=text)
 
 
 
 
 
61
 
62
  def main():
63
  try:
@@ -87,22 +92,16 @@ def main():
87
 
88
  debug_print("Iniciando autenticação com Twitter...")
89
 
90
- # Autenticação com Twitter para leitura
91
  client = tweepy.Client(
92
  bearer_token=os.getenv('TWITTER_BEARER_TOKEN'),
 
 
 
 
93
  wait_on_rate_limit=True
94
  )
95
 
96
- # Autenticação com Twitter para postagem
97
- auth = tweepy.OAuth1UserHandler(
98
- os.getenv('TWITTER_API_KEY'),
99
- os.getenv('TWITTER_API_SECRET_KEY'),
100
- os.getenv('TWITTER_ACCESS_TOKEN'),
101
- os.getenv('TWITTER_ACCESS_TOKEN_SECRET')
102
- )
103
-
104
- api = tweepy.API(auth, wait_on_rate_limit=True)
105
-
106
  # Vamos testar a autenticação com uma query simples
107
  debug_print("Testando autenticação...")
108
  try:
@@ -208,9 +207,13 @@ def main():
208
  # Postar tweet
209
  with st.spinner('Postando tweet...'):
210
  debug_print("Tentando postar tweet...")
211
- post_tweet(api, generated_text)
212
- st.success("Tweet postado com sucesso!")
213
- debug_print("Tweet postado com sucesso")
 
 
 
 
214
 
215
  # Interface Streamlit
216
  st.title("Resultados da Análise")
 
56
  wait=wait_exponential(multiplier=1, min=4, max=10),
57
  retry=lambda e: isinstance(e, tweepy.errors.TooManyRequests)
58
  )
59
+ def post_tweet(client, text):
60
+ try:
61
+ response = client.create_tweet(text=text)
62
+ return response
63
+ except Exception as e:
64
+ debug_print(f"Erro ao postar tweet: {str(e)}")
65
+ raise e
66
 
67
  def main():
68
  try:
 
92
 
93
  debug_print("Iniciando autenticação com Twitter...")
94
 
95
+ # Autenticação com Twitter para leitura e escrita
96
  client = tweepy.Client(
97
  bearer_token=os.getenv('TWITTER_BEARER_TOKEN'),
98
+ consumer_key=os.getenv('TWITTER_API_KEY'),
99
+ consumer_secret=os.getenv('TWITTER_API_SECRET_KEY'),
100
+ access_token=os.getenv('TWITTER_ACCESS_TOKEN'),
101
+ access_token_secret=os.getenv('TWITTER_ACCESS_TOKEN_SECRET'),
102
  wait_on_rate_limit=True
103
  )
104
 
 
 
 
 
 
 
 
 
 
 
105
  # Vamos testar a autenticação com uma query simples
106
  debug_print("Testando autenticação...")
107
  try:
 
207
  # Postar tweet
208
  with st.spinner('Postando tweet...'):
209
  debug_print("Tentando postar tweet...")
210
+ try:
211
+ post_tweet(client, generated_text)
212
+ st.success("Tweet postado com sucesso!")
213
+ debug_print("Tweet postado com sucesso")
214
+ except Exception as e:
215
+ st.error(f"Erro ao postar tweet: {str(e)}")
216
+ debug_print(f"Erro ao postar tweet: {str(e)}")
217
 
218
  # Interface Streamlit
219
  st.title("Resultados da Análise")