announcer.py - added mailing support

This commit is contained in:
Nephirus 2011-05-25 18:02:14 +02:00
parent 5500fb8eb1
commit eaf5c42df1

View file

@ -1,23 +1,24 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*-
import re import re
import urllib2 import urllib2
import datetime import datetime
import time import smtplib
from email.mime.text import MIMEText
url = "http://brmlab.cz/_export/raw/event/start" url = "http://brmlab.cz/_export/raw/event/start"
src = urllib2.urlopen(url) smtp_server = "localhost"
dest_addr = "announcer-test@kerestes.cz"
src = urllib2.urlopen(url)
now = datetime.datetime.now() now = datetime.datetime.now()
lines = [] lines = []
l2 = [] l2 = []
out = []
#print src.readline()
for line in src : for line in src :
# print line
match = re.match(r" \* [0-9]",line) match = re.match(r" \* [0-9]",line)
if match is not None: if match is not None:
lines.append(line) lines.append(line)
@ -33,24 +34,32 @@ for line in l2:
# event page s popiskem # event page s popiskem
a = re.match(r" \* (.*) \[\[event:(.*)\|(.*)\]\]", line) a = re.match(r" \* (.*) \[\[event:(.*)\|(.*)\]\]", line)
if a is not None: if a is not None:
print(a.group(1) + " " + a.group(3) + " - " + " http://brmlab.cz/event/" + a.group(2)) out.append(a.group(1) + " " + a.group(3) + " - " + " http://brmlab.cz/event/" + a.group(2))
continue continue
# event page bez popisku # event page bez popisku
a = re.match(r" \* (.*) \[\[event:(.*)\]\]", line) a = re.match(r" \* (.*) \[\[event:(.*)\]\]", line)
if a is not None: if a is not None:
print(a.group(1) + " " + "http://brmlab.cz/event/" + a.group(2)) out.append(a.group(1) + " " + "http://brmlab.cz/event/" + a.group(2))
continue continue
# link s popiskem # link s popiskem
a = re.match(r" \* (.*) \[\[(?<!event)(.*)\|(.*)\]\]", line) a = re.match(r" \* (.*) \[\[(?<!event)(.*)\|(.*)\]\]", line)
if a is not None: if a is not None:
print(a.group(1) + " " + a.group(3) + " - " + a.group(2)) out.append(a.group(1) + " " + a.group(3) + " - " + a.group(2))
continue continue
# ostatni # ostatni
a = re.match(r" \* (.*)", line) a = re.match(r" \* (.*)", line)
if a is not None: if a is not None:
print(a.group(1)) out.append(a.group(1))
msg = MIMEText("".join(out))
msg['Subject'] = "Týdenní přehled událostí"
msg['From'] = "noreply@brmlab.cz"
msg['To'] = dest_addr
msg._charset = "utf-8"
if out.__len__() > 0:
s = smtplib.SMTP(smtp_server)
s.sendmail("noreply@brmlab.cz", dest_addr, msg.as_string())