Skip to content

Instantly share code, notes, and snippets.

@Theasker
Last active May 5, 2021 19:42
Show Gist options
  • Select an option

  • Save Theasker/7d72c0aa07482e61feb2488a6658486f to your computer and use it in GitHub Desktop.

Select an option

Save Theasker/7d72c0aa07482e61feb2488a6658486f to your computer and use it in GitHub Desktop.
Telegram bot with scrap and scheduler in Python
# thanks to https://platzi.com/blog/bot-python/
from bs4 import BeautifulSoup #del módulo bs4, necesitamos BeautifulSoup
import requests
import schedule
import time
def bot_send_text(bot_message):
bot_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# bot_chatID = '8310736'
bot_chatID = '-430895359'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
print(response)
return response
def btc_scraping():
url = requests.get('https://awebanalysis.com/es/coin-details/bitcoin/')
soup = BeautifulSoup(url.content, 'html.parser')
type(soup)
# <td class="wbreak_word align-middle coin_price">$58,739.78</td>
result = soup.find('td', {'class': "wbreak_word align-middle coin_price"})
format_result = result.text
return result.text
def report():
text = time.strftime("%x %X") + " - BTC - " + btc_scraping()
test_bot = bot_send_text(text)
if __name__ == '__main__':
schedule.every().day.at("08:00").do(report)
# schedule.every(2).minutes.do(report2)
#schedule.every(3).seconds.do(report2)
while True:
schedule.run_pending()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment