pink-mothra commited on
Commit
b9ebb1b
·
1 Parent(s): 450e6ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import telebot
4
+
5
+ import requests
6
+
7
+ BOT_TOKEN = os.environ.get('BOT_TOKEN')
8
+
9
+ bot = telebot.TeleBot(BOT_TOKEN)
10
+
11
+
12
+ @bot.message_handler(commands=['start', 'hello'])
13
+ def send_welcome(message):
14
+ bot.reply_to(message, "Posso gerar números aleatórios verdadeiros")
15
+
16
+ @bot.message_handler(commands=['aleatorio'])
17
+
18
+ def sign_handler(message):
19
+ text = "Por favor escolha um tipo de dado:\nuint8 (Inteiros 0–255), uint16 (Inteiros 0–65535)"
20
+ bot.reply_to(message, text)
21
+
22
+ bot.register_next_step_handler(message, process_data_type_choice)
23
+
24
+ def process_data_type_choice(message):
25
+
26
+ data_type = message.text
27
+
28
+
29
+ bot.reply_to(message, "Por favor, escolha o comprimento da matriz. O valor deve variar de 1 a 1024.")
30
+
31
+ bot.register_next_step_handler(message, lambda msg: process_array_length_choice(msg, data_type))
32
+
33
+ def process_array_length_choice(message, data_type):
34
+
35
+ array_length = message.text
36
+
37
+
38
+ api_url = f"https://qrng.anu.edu.au/API/jsonI.php?length={array_length}&type={data_type}"
39
+
40
+
41
+ try:
42
+ response = requests.get(api_url)
43
+ response.raise_for_status()
44
+
45
+
46
+ result = response.json()
47
+
48
+
49
+ random_data = result.get('data', [])
50
+
51
+
52
+ bot.reply_to(message, f"Números aleatórios verdadeiros: {random_data}")
53
+
54
+ except requests.exceptions.RequestException as e:
55
+
56
+ bot.reply_to(message, f"Aguarde 1 min depois da ultima solicitação")
57
+
58
+
59
+ bot.infinity_polling()