mirror of
https://github.com/brmlab/misc.git
synced 2025-06-08 18:04:08 +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
30
announcer.py
30
announcer.py
|
@ -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())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue