Skip to content

Instantly share code, notes, and snippets.

@amirulabu
Created February 7, 2019 00:11
Show Gist options
  • Save amirulabu/33a4c82f3a0f1b27a6a34e5847cb7ddf to your computer and use it in GitHub Desktop.
Save amirulabu/33a4c82f3a0f1b27a6a34e5847cb7ddf to your computer and use it in GitHub Desktop.
A simple telegram bot that notifies whether some website is up or not. Install requests library, setup crontab and your done!
#!/usr/bin/python3
import requests
r = requests.get('<your website>')
if r.status_code is 200:
r = requests.post(
'https://api.telegram.org/bot<your telegram bot token>/sendMessage',
data = {'chat_id':<your telegram chat id>,'text':'Good news, Status code for %s is %s' % (r.url,r.status_code),
'disable_notification': True}
)
else:
r = requests.post(
'https://api.telegram.org/bot<your telegram bot token>/sendMessage',
data = {'chat_id':<your telegram chat id>,'text':'Bad news, Status code for %s is %s' % (r.url,r.status_code)}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment