Skip to content

Instantly share code, notes, and snippets.

@53845714nF
Last active April 26, 2024 07:52
Show Gist options
  • Save 53845714nF/1b493ab8a19cc912b7dbb2c6cd66d612 to your computer and use it in GitHub Desktop.
Save 53845714nF/1b493ab8a19cc912b7dbb2c6cd66d612 to your computer and use it in GitHub Desktop.
Checks if my timetable has become available.
import json
import time
import requests
from bs4 import BeautifulSoup
# Telegram Variables
URL = 'https://api.telegram.org/bot'
TOKEN = '<Your Token>'
chat_id = '<Your Chat ID>'
THB_TIMETABLE_URL = "https://informatik.th-brandenburg.de/Stundenplan/ws2324/plan/infb-5-1.html"
def timetable_activ(url):
'''
This function look for the status of the timetable
:param url: The URL THB timetable
:return: bool activ
'''
response = requests.get(url)
# BeautifulSoup HTML-Dokument aus dem Quelltext parsen
html = BeautifulSoup(response.text, 'html.parser')
# Status ermitteln
title = html.find('title')
if title.text == "Dieser Raum ist nicht belegt":
return False
else:
return True
def response(text):
'''
This function sends Messages by a response to keywords.
'''
requests.post(URL + TOKEN + '/sendMessage', data={'chat_id': chat_id,
'text': text
})
def main(args):
if timetable_activ(THB_TIMETABLE_URL):
response('Stundenplan ist verfügbar.')
return { 'body': 'Stundenplan ist verfügbar.'}
return {'body': 'Noch nich da'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment