Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import random
|
3 |
+
|
4 |
+
API_TOKEN = "mlsn.7761a3939b08b19f4c13e05666a346cfb4967e509c80e4cd92bf3a7d1aa4e7ca"
|
5 |
+
|
6 |
+
# Lista de perguntas aleat贸rias
|
7 |
+
perguntas = [
|
8 |
+
"Quem foi Alan Turing?",
|
9 |
+
"O que 茅 Machine Learning?",
|
10 |
+
"Python 茅 melhor que C++?",
|
11 |
+
"Qual a capital da Isl芒ndia?",
|
12 |
+
"Como funciona blockchain?",
|
13 |
+
"O que 茅 amor verdadeiro em algoritmos?"
|
14 |
+
]
|
15 |
+
|
16 |
+
def buscar_duck(pergunta):
|
17 |
+
url = f"https://api.duckduckgo.com/?q={pergunta}&format=json&no_redirect=1&no_html=1"
|
18 |
+
resposta = requests.get(url)
|
19 |
+
data = resposta.json()
|
20 |
+
abstract = data.get("AbstractText")
|
21 |
+
return abstract if abstract else "DuckDuckGo ficou t铆mido e n茫o respondeu nada 馃槩"
|
22 |
+
|
23 |
+
def enviar_email(para, assunto, mensagem):
|
24 |
+
url = "https://api.mailersend.com/v1/email"
|
25 |
+
|
26 |
+
headers = {
|
27 |
+
"Authorization": f"Bearer {API_TOKEN}",
|
28 |
+
"Content-Type": "application/json"
|
29 |
+
}
|
30 |
+
|
31 |
+
payload = {
|
32 |
+
"from": {
|
33 |
+
"email": "[email protected]", # tem que ser verificado no MailerSend
|
34 |
+
"name": "Agente Nina 馃拫"
|
35 |
+
},
|
36 |
+
"to": [{
|
37 |
+
"email": para,
|
38 |
+
"name": "Meu Hackerzinho"
|
39 |
+
}],
|
40 |
+
"subject": assunto,
|
41 |
+
"text": mensagem
|
42 |
+
}
|
43 |
+
|
44 |
+
response = requests.post(url, headers=headers, json=payload)
|
45 |
+
print(f"Status: {response.status_code}")
|
46 |
+
print(response.text)
|
47 |
+
|
48 |
+
def agente_do_caos():
|
49 |
+
pergunta = random.choice(perguntas)
|
50 |
+
resposta = buscar_duck(pergunta)
|
51 |
+
assunto = f"Resposta aleat贸ria: {pergunta}"
|
52 |
+
mensagem = f"Pergunta: {pergunta}\n\nResposta: {resposta}"
|
53 |
+
enviar_email("[email protected]", assunto, mensagem)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
agente_do_caos()
|