-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (34 loc) · 1.36 KB
/
main.py
File metadata and controls
46 lines (34 loc) · 1.36 KB
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
import openai
openai.api_key = "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"
import tweepy
# Autentica la aplicación de Twitter utilizando las claves de acceso
auth = tweepy.OAuth2BearerHandler("AAAAAAAAAAAAAAAAAAAAACFelAEAAAAAazOrc9K%2BbvpSZ58ggsacVWOhGRQ%3DWUB8Ow6Z2lAJKoQkuq4qLG0poqEG8jtY57O1eQu1dakU5bb7EX")
api = tweepy.API(auth)
# Recupera las tendencias más recientes de Twitter
trends = api.get_place_trends(2972)
for obj in trends:
for trend in obj["trends"]:
print(trend["name"])
#trend_list = trends[0]["trends"]
#trends = [trend["name"] for trend in trend_list]
#print(f"Las tendencias más recientes en Twitter son: {}")
# Utiliza ChatGPT para escribir un artículo sobre las tenden
def generate_text(prompt, model):
completions = openai.Completion.create(
engine=model,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip()
# Utiliza ChatGPT para escribir un artículo sobre las tendencias más recientes en Twitter
article = ""
for trend in trends:
prompt = f"Escribe un artículo sobre la tendencia en Twitter '{trend}'"
model = "text-davinci-002"
article += generate_text(prompt, model)
# Imprime el artículo generado por ChatGPT
print(article)