Last active
July 1, 2018 21:30
-
-
Save nebil/ce6904ad6ffc8914f436b3dbbc94de23 to your computer and use it in GitHub Desktop.
🤖 Un bot que inspecciona si existe disponibilidad en Telegram 🤖
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
""" | |
Vamos Testingo: dime si @nebil está libre. | |
Este breve script debería funcionar con cualquier versión de Python 3. | |
Además, utiliza 'beautifulsoup4', que es la única dependencia externa. | |
Por cierto, (probablemente no) es importante señalar que, | |
bajo el propósito de aumentar la portabilidad del código, | |
este script busca depender --de forma razonable, espero-- | |
de la menor cantidad de librerías _third-party_. | |
Dicho en otras palabras: lo lamento, 'requests'. | |
""" | |
from time import sleep as nap | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup | |
TELEGRAM = 'https://api.telegram.org/bot' | |
TEMPLATE = TELEGRAM + '{}/sendMessage?chat_id={}&text={}&parse_mode=Markdown' | |
if __name__ == '__main__': | |
settings = dict(line.rstrip().split('=') for line in open('testingo.ini')) | |
token, id_, hours = map(settings.get, ('bot_token', 'chat_id', 'naptime')) | |
while True: | |
contents = urlopen('https://t.me/nebil').read() | |
soup = BeautifulSoup(contents, 'html.parser') | |
page = soup.find(class_='tgme_page_title') | |
text = page.text if page else '**Libre.**' | |
urlopen(TEMPLATE.format(token, id_, text)) | |
nap(int(hours) * 60 * 60) |
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
bot_token=<token> | |
chat_id=<number> | |
naptime=<hours> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment