File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # encoding: utf-8
3
+
4
+ '''Robô Ed Telegram Bot'''
5
+
6
+ __author__ = 'leandrotoledodesouza@gmail.com'
7
+
8
+ import telegram
9
+ import requests
10
+
11
+
12
+ def main ():
13
+ bot = telegram .Bot ('token' ) # Telegram Bot Authorization Token
14
+
15
+ global LAST_UPDATE_ID
16
+ LAST_UPDATE_ID = bot .getUpdates ()[- 1 ].update_id # Get lastest update
17
+
18
+ while True :
19
+ for update in bot .getUpdates (offset = LAST_UPDATE_ID ):
20
+ text = update .message .text
21
+ chat_id = update .message .chat .id
22
+ update_id = update .update_id
23
+
24
+ if LAST_UPDATE_ID < update_id : # If newer than the initial
25
+ # LAST_UPDATE_ID
26
+ if text :
27
+ roboed = ed (text ) # Ask something to Robô Ed
28
+ bot .sendMessage (chat_id = chat_id , text = roboed )
29
+ LAST_UPDATE_ID = update_id
30
+
31
+
32
+ def ed (text ):
33
+ url = 'http://www.ed.conpet.gov.br/mod_perl/bot_gateway.cgi?server=0.0.0.0%3A8085&charset_post=utf-8&charset=utf-8&pure=1&js=0&tst=1&msg=' + text
34
+ data = requests .get (url ).content
35
+
36
+ return data .strip ()
37
+
38
+ if __name__ == '__main__' :
39
+ main ()
You can’t perform that action at this time.
0 commit comments