mirror of
https://github.com/brmlab/misc.git
synced 2025-06-08 01:44:47 +02:00
add small introduction to message body, small adjustements of code
This commit is contained in:
parent
07c12d606a
commit
f64bd76531
1 changed files with 16 additions and 14 deletions
24
announcer.py
24
announcer.py
|
@ -15,7 +15,7 @@ src = urllib2.urlopen(url)
|
|||
now = datetime.datetime.now()
|
||||
|
||||
lines = []
|
||||
l2 = []
|
||||
weeklines = []
|
||||
out = []
|
||||
|
||||
for line in src:
|
||||
|
@ -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" \* (.*) \[\[(?<!event)(.*)\|(.*)\]\]", line)
|
||||
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
|
||||
|
||||
# ostatni
|
||||
a = re.match(r" \* (.*)", line)
|
||||
if a is not None:
|
||||
out.append(a.group(1) + "\n")
|
||||
out.append(a.group(1))
|
||||
|
||||
msg = MIMEText("".join(out), _charset="utf-8")
|
||||
msg['Subject'] = "Týdenní přehled událostí"
|
||||
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
|
||||
|
||||
if out.__len__() > 0:
|
||||
s = smtplib.SMTP(smtp_server)
|
||||
s.sendmail("noreply@brmlab.cz", dest_addr, msg.as_string())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue