add small introduction to message body, small adjustements of code

This commit is contained in:
Pavol Rusnak 2011-05-30 00:23:48 +02:00
parent 07c12d606a
commit f64bd76531

View file

@ -15,10 +15,10 @@ src = urllib2.urlopen(url)
now = datetime.datetime.now() now = datetime.datetime.now()
lines = [] lines = []
l2 = [] weeklines = []
out = [] out = []
for line in src : for line in src:
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)
@ -28,37 +28,39 @@ for line in lines:
if a is not None: if a is not None:
diff = datetime.datetime.strptime(a.group(1),"%d.%m.%Y") - now diff = datetime.datetime.strptime(a.group(1),"%d.%m.%Y") - now
if diff < datetime.timedelta(weeks=1) and diff >= datetime.timedelta(days=0): if diff < datetime.timedelta(weeks=1) and diff >= datetime.timedelta(days=0):
l2.append(line) weeklines.append(line)
for line in l2: for line in weeklines:
# 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:
out.append(a.group(1) + " " + a.group(3) + " - " + " http://brmlab.cz/event/" + a.group(2) + "\n") out.append("%s %s - http://brmlab.cz/event/%s" % (a.group(1), a.group(3), 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:
out.append(a.group(1) + " " + "http://brmlab.cz/event/" + a.group(2) + "\n") out.append("%s - http://brmlab.cz/event/%s" % (a.group(1), 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:
out.append(a.group(1) + " " + a.group(3) + " - " + a.group(2) + "\n") out.append("%s %s - %s" % (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:
out.append(a.group(1) + "\n") out.append(a.group(1))
msg = MIMEText("".join(out), _charset="utf-8") if len(out):
msg['Subject'] = "Týdenní přehled událostí" out.insert(0, "")
msg['From'] = "noreply@brmlab.cz" out.insert(0, "Events taking place in brmlab this week:")
msg['To'] = dest_addr out.insert(0, "Udalosti v brmlabu tento tyden:")
msg = MIMEText("\n".join(out), _charset="utf-8")
if out.__len__() > 0: msg['Subject'] = "Tydenni prehled udalosti / Weekly overview of events"
msg['From'] = "noreply@brmlab.cz"
msg['To'] = dest_addr
s = smtplib.SMTP(smtp_server) s = smtplib.SMTP(smtp_server)
s.sendmail("noreply@brmlab.cz", dest_addr, msg.as_string()) s.sendmail("noreply@brmlab.cz", dest_addr, msg.as_string())