Last active
January 3, 2022 00:46
-
-
Save LuigiImVector/c748aa5801c8f3fdfeb4114eb35d1eac to your computer and use it in GitHub Desktop.
Telegram bot of F.P.B. - Concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telebot # https://github.com/eternnoir/pyTelegramBotAPI | |
import requests | |
bot = telebot.TeleBot('BOT_TOKEN_HERE') # Create a bot on t.me/BotFather | |
r = requests.get('https://raw.githubusercontent.com/EbookFoundation/free-programming-books/master/books/free-programming-books-it.md') | |
f = r.text | |
f = f.splitlines() | |
# try to write "Android", "C", "Ruby"... to the bot | |
@bot.message_handler(func=lambda message: True) | |
def echo_message(message): | |
t = message.json | |
cerca = "### " + str(t['text']) | |
print(cerca) | |
check = False | |
firstLine = False | |
text = "" | |
for line in f: | |
if line == cerca: | |
check = True | |
if check and line == "": | |
if firstLine: | |
check = False | |
firstLine = False | |
else: | |
firstLine = True | |
if check: | |
text = text + line + "\n" | |
text = text.replace("*", "-") | |
text = text.replace("#", "") | |
print(text) | |
bot.reply_to(message, text, parse_mode="markdown") | |
if __name__ == '__main__': | |
bot.infinity_polling() # keep running even if there are errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment