-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannouncer.py
executable file
·67 lines (56 loc) · 1.77 KB
/
announcer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import urllib2
import datetime
import smtplib
from email.mime.text import MIMEText
url = "http://brmlab.cz/_export/raw/event/start"
smtp_server = "localhost"
dest = ("[email protected]", "[email protected]")
src = urllib2.urlopen(url)
now = datetime.datetime.now()
lines = []
weeklines = []
out = []
for line in src:
match = re.match(r" \* [0-9]",line)
if match is not None:
lines.append(line)
for line in lines:
a = re.match(r" \* (.*?) (.*)", line)
if a is not None:
diff = datetime.datetime.strptime(a.group(1),"%d.%m.%Y") - now
if diff < datetime.timedelta(weeks=1) and diff >= datetime.timedelta(days=-1):
weeklines.append(line)
for line in weeklines:
# event page s popiskem
a = re.match(r" \* (.*) \[\[event:(.*)\|(.*)\]\]", line)
if a is not None:
out.append("%s %s - http://brmlab.cz/event/%s" % (a.group(1), a.group(3), a.group(2)))
continue
# event page bez popisku
a = re.match(r" \* (.*) \[\[event:(.*)\]\]", line)
if a is not None:
out.append("%s - http://brmlab.cz/event/%s" % (a.group(1), a.group(2)))
continue
# link s popiskem
a = re.match(r" \* (.*) \[\[(?<!event)(.*)\|(.*)\]\]", line)
if a is not None:
out.append("%s %s - %s" % (a.group(1), a.group(3), a.group(2)))
continue
# ostatni
a = re.match(r" \* (.*)", line)
if a is not None:
out.append(a.group(1))
if len(out):
out.insert(0, "")
out.insert(0, "Events taking place in brmlab this week:")
out.insert(0, "Udalosti v brmlabu tento tyden:")
msg = MIMEText("\n".join(out), _charset="utf-8")
msg['Subject'] = "Tydenni prehled udalosti / Weekly overview of events"
msg['From'] = "[email protected]"
s = smtplib.SMTP(smtp_server)
for addr in dest:
msg['To'] = addr
s.sendmail("[email protected]", addr, msg.as_string())