mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-27 08:50:38 +01:00
Adding RoboEd as example
This commit is contained in:
parent
635fae04e6
commit
c3ea91e68c
1 changed files with 39 additions and 0 deletions
39
examples/roboed.py
Normal file
39
examples/roboed.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
'''Robô Ed Telegram Bot'''
|
||||
|
||||
__author__ = 'leandrotoledodesouza@gmail.com'
|
||||
|
||||
import telegram
|
||||
import requests
|
||||
|
||||
|
||||
def main():
|
||||
bot = telegram.Bot('token') # Telegram Bot Authorization Token
|
||||
|
||||
global LAST_UPDATE_ID
|
||||
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id # Get lastest update
|
||||
|
||||
while True:
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
|
||||
text = update.message.text
|
||||
chat_id = update.message.chat.id
|
||||
update_id = update.update_id
|
||||
|
||||
if LAST_UPDATE_ID < update_id: # If newer than the initial
|
||||
# LAST_UPDATE_ID
|
||||
if text:
|
||||
roboed = ed(text) # Ask something to Robô Ed
|
||||
bot.sendMessage(chat_id=chat_id, text=roboed)
|
||||
LAST_UPDATE_ID = update_id
|
||||
|
||||
|
||||
def ed(text):
|
||||
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
|
||||
data = requests.get(url).content
|
||||
|
||||
return data.strip()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Reference in a new issue