meetings.py 1.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
from server import *
import icalendar
import requests

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()
			if 'VIDEO' != event['SUMMARY'].upper() or start < now or start > now+delta:
				continue
			meetings.append(event)
		except:
			pass
	if not meetings:
		return
	event = sorted(meetings, key=lambda e: e['DTSTART'].dt)[0]
	return str(event['UID']), event['DTSTART'].dt.replace(tzinfo=None)

24
@sched_func(60*60)
25 26 27 28 29 30 31 32 33 34
def update_meeting():
	try:
		uid, start = get_next_meeting()
	except:
		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())