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
# -*- coding: utf-8 -*-
import re
import urllib2
import datetime
import time
import smtplib
from email.mime.text import MIMEText
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()
lines = []
l2 = []
#print src.readline()
out = []
for line in src :
# print line
match = re.match(r" \* [0-9]",line)
if match is not None:
lines.append(line)
@ -33,24 +34,32 @@ for line in l2:
# event page s popiskem
a = re.match(r" \* (.*) \[\[event:(.*)\|(.*)\]\]", line)
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
# event page bez popisku
a = re.match(r" \* (.*) \[\[event:(.*)\]\]", line)
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
# link s popiskem
a = re.match(r" \* (.*) \[\[(?<!event)(.*)\|(.*)\]\]", line)
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
# ostatni
a = re.match(r" \* (.*)", line)
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())