Skip to content

Instantly share code, notes, and snippets.

@muety
Created October 3, 2017 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muety/57e1ee3c3ae9584dd2282832b71246df to your computer and use it in GitHub Desktop.
Save muety/57e1ee3c3ae9584dd2282832b71246df to your computer and use it in GitHub Desktop.
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