diff --git a/announcer.py b/announcer.py index e6d9b9b..36b9185 100755 --- a/announcer.py +++ b/announcer.py @@ -15,10 +15,10 @@ src = urllib2.urlopen(url) now = datetime.datetime.now() lines = [] -l2 = [] +weeklines = [] out = [] -for line in src : +for line in src: match = re.match(r" \* [0-9]",line) if match is not None: lines.append(line) @@ -28,37 +28,39 @@ for line in lines: 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=0): - l2.append(line) + weeklines.append(line) -for line in l2: +for line in weeklines: # event page s popiskem a = re.match(r" \* (.*) \[\[event:(.*)\|(.*)\]\]", line) 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 # event page bez popisku a = re.match(r" \* (.*) \[\[event:(.*)\]\]", line) 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 # link s popiskem a = re.match(r" \* (.*) \[\[(? 0: +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'] = "noreply@brmlab.cz" + msg['To'] = dest_addr s = smtplib.SMTP(smtp_server) s.sendmail("noreply@brmlab.cz", dest_addr, msg.as_string())