Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Watch for exam results announcement and notify via telegram-middleman-bot (run as Cronjob)
import requests
import os
url = 'http://www.zar.kit.edu/rss/feed.rss'
keywords = ['steuerrecht']
cache_file = 'cache.txt'
hook_url = 'http://middleman.ferdinand-muetsch.de/api/messages'
hook_sender_id = 'Watcher'
hook_recipient_id = ''
def callback(keyword):
json_data = {
'recipient_token': hook_recipient_id,
'origin': hook_sender_id,
'text': 'Found word *{}* at [{}]({})'.format(keyword, url, url)
}
requests.post(hook_url, json=json_data)
if __name__ is '__main__':
text_new, text_old = '', ''
if not os.path.exists(cache_file): open(cache_file, 'a', encoding='utf8').close()
with open(cache_file, 'r', encoding='utf8') as f:
text_old = f.read()
r = requests.get(url)
text_new = r.text.lower()
for k in keywords:
if k.lower() in text_new and not k.lower() in text_old:
callback(k)
break
with open(cache_file, 'w', encoding='utf8') as f:
f.write(text_new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.