Last active
May 15, 2016 11:39
-
-
Save sevazhidkov/22202e6aacc22ab5c7366a624420cc32 to your computer and use it in GitHub Desktop.
Скрипт, который отправляет СМС, когда сайт ЛКШ меняется
This file contains hidden or 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 time | |
import hashlib | |
import requests | |
LKSH_PAGE = 'https://lksh.ru' | |
SMS_RU_PHONE_NUMBER = 'XXX' | |
SMS_RU_ENDPOINT = 'http://sms.ru/sms/send?api_id={}&to={}&text={}' | |
SMS_RU_TOKEN = 'XXX' | |
CHANGE_SMS = 'LKSH site has something new for you :)' | |
def lksh_page_hash(): | |
content = requests.get(LKSH_PAGE).text | |
content_hash = hashlib.md5() | |
content_hash.update(content.encode('utf-8')) | |
return content_hash.digest() | |
def notificate(): | |
response = requests.get(SMS_RU_ENDPOINT.format( | |
SMS_RU_TOKEN, SMS_RU_PHONE_NUMBER, CHANGE_SMS | |
)) | |
print('SMS status', response.text) | |
# Setup | |
print('Starting') | |
previous_hash = lksh_page_hash() | |
print('Current hash', previous_hash) | |
# Main loop | |
while True: | |
current_hash = lksh_page_hash() | |
if current_hash != previous_hash: | |
print('DETECTED CHANGE ON', LKSH_PAGE) | |
notificate() | |
previous_hash = current_hash | |
time.sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment