Skip to content

Commit c3ea91e

Browse files
committed
Adding RoboEd as example
1 parent 635fae0 commit c3ea91e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/roboed.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy