meetings.py 1.17 KB
Newer Older
1 2 3
import icalendar
import requests

4 5
from server import *

6 7 8 9 10 11 12 13 14
def get_next_meeting():
	ical = requests.get(config['ICAL_URL']).content
	events = icalendar.Calendar.from_ical(ical).walk('VEVENT')
	now = datetime.now().date()
	delta = timedelta(weeks=2)
	meetings = []
	for event in events:
		try:
			start = event['DTSTART'].dt.date()
15
			if event['SUMMARY'].upper() != 'VIDEO' or start < now or start > now+delta:
16 17
				continue
			meetings.append(event)
18
		except KeyError:
19 20
			pass
	if not meetings:
21
		return None, None
22 23 24
	event = sorted(meetings, key=lambda e: e['DTSTART'].dt)[0]
	return str(event['UID']), event['DTSTART'].dt.replace(tzinfo=None)

25
@sched_func(60*60)
26
def update_meeting():
27 28
	uid, start = get_next_meeting()
	if uid is None:
29 30 31 32 33 34
		return
	text = 'Die nächste Video AG-Sitzung findet am %s ab %s Uhr in den Räumlichkeiten der Fachschaft im Augustinerbach 2a statt.'%(
			human_date(start), human_time(start))
	modify('''REPLACE INTO announcements
			(extid, text, level, visible, time_publish, time_expire, time_created, time_updated, created_by)
			VALUES (?, ?, 0, 1, ?, ?, ?, ?, 0)''',
35
		'ical:'+uid, text, start-timedelta(days=7), start+timedelta(hours=2), datetime.now(), datetime.now())