Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ansible-warpzone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infrastruktur
ansible-warpzone
Commits
61c23913
Commit
61c23913
authored
4 months ago
by
zweigs
Committed by
jabertwo
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Tested sendmail_plenum.py update
parent
86f7e433
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webserver/docker_dokuwiki/templates/sendmail_plenum.py
+84
-38
84 additions, 38 deletions
webserver/docker_dokuwiki/templates/sendmail_plenum.py
with
84 additions
and
38 deletions
webserver/docker_dokuwiki/templates/sendmail_plenum.py
+
84
−
38
View file @
61c23913
...
...
@@ -3,8 +3,21 @@ import datetime
from
email.message
import
EmailMessage
from
email.utils
import
formatdate
import
requests
import
time
import
os
def
do_work
():
def
wait_until_unlocked
():
# Wait for locks to be released
# If you don't do this and edit DokuWiki pages, others may overwrite what you do
locked
=
True
while
locked
:
locked
=
os
.
path
.
isfile
(
"
/srv/dokuwiki/data/data/locks/e0bc4d991c71e981423bfefd6d257985.lock
"
)
# Avoid busy loop
if
locked
:
time
.
sleep
(
5
)
def
get_topics
():
with
open
(
"
/srv/dokuwiki/data/data/pages/intern/diskussionsthemen.txt
"
)
as
fp
:
raw
=
fp
.
read
().
split
(
'
\n
'
)
...
...
@@ -13,12 +26,12 @@ def do_work():
lastline
=
0
for
index
,
line
in
enumerate
(
raw
):
# Start marker
if
"
====== 1.
"
in
line
:
if
"
====== 1.
"
in
line
and
not
"
1.5
"
in
line
:
firstline
=
index
+
1
continue
# End marker
if
"
====== 2.
"
in
line
:
if
"
====== 2.
"
in
line
or
"
====== 1.5
"
in
line
:
lastline
=
index
break
...
...
@@ -27,51 +40,84 @@ def do_work():
for
extracted
in
raw
[
firstline
:
lastline
]:
if
extracted
!=
''
:
topics
.
append
(
extracted
)
return
topics
# There are no topics - just exit
if
(
len
(
topics
)
==
0
):
return
True
def
send_mail
(
topics
,
date
):
# mail template
mail
=
f
"""
Liebe Zonies,
es gibt wieder Themen die im Plenum besprochen werden sollen. Der nächste
Reguläre Termin ist am nächsten Dienstag (
{
str
(
date
)
}
) um 20:00.
Im Wiki (https://wiki.warpzone.ms/intern:diskussionsthemen#diskussionsthemen_naechstes_plenum_automatische_einladung)
stehen folgende Themen:
# calculate date of next tuesday
d
=
datetime
.
date
.
today
()
while
d
.
strftime
(
'
%a
'
)
!=
'
Tue
'
:
d
+=
datetime
.
timedelta
(
1
)
{
chr
(
10
).
join
(
topics
)
}
# mail template
mail
=
f
"""
Liebe Zonies,
es gibt wieder Themen die im Plenum besprochen werden sollen. Der nächste
Reguläre Termin ist am nächsten Dienstag (
{
str
(
d
)
}
) um 20:00.
Im Wiki (https://wiki.warpzone.ms/intern:diskussionsthemen#diskussionsthemen_naechstes_plenum_automatische_einladung)
stehen folgende Themen:
Die Teilnahme ist natürlich auch remote möglich unter
https://jitsi.dorf-post.de/warpzone-plenum möglich.
{
chr
(
10
).
join
(
topics
)
}
Viele Grüße und bis Dienstag,
Die Teilnahme ist natürlich auch remote möglich unter
https://jitsi.dorf-post.de/warpzone-plenum möglich.
sendmail_plenum.py
"""
Viele Grüße und bis Dienstag,
msg
=
EmailMessage
()
msg
[
'
Subject
'
]
=
f
'
Aktuelle Plenumsthemen für Dienstag (
{
str
(
date
)
}
20:00)
'
msg
[
'
From
'
]
=
'
{{noreply_email_user}}
'
msg
[
'
To
'
]
=
'
intern@warpzone.ms
'
msg
[
'
Date
'
]
=
formatdate
(
localtime
=
True
)
msg
.
set_content
(
mail
)
server
=
smtplib
.
SMTP
(
'
{{smtp_host}}
'
,
{{
smtp_port
}})
server
.
starttls
()
server
.
login
(
"
{{noreply_email_user}}
"
,
"
{{noreply_email_pass}}
"
)
server
.
send_message
(
msg
)
server
.
quit
()
return
True
sendmail_plenum.py
"""
def
update_page
(
label
):
with
open
(
"
/srv/dokuwiki/data/data/pages/intern/diskussionsthemen.txt
"
)
as
fp
:
raw
=
fp
.
read
().
split
(
'
\n
'
)
new_content
=
[]
topic_replaced
=
False
for
old_line
in
raw
:
new_content
.
append
(
old_line
)
msg
=
EmailMessage
()
msg
[
'
Subject
'
]
=
f
'
Aktuelle Plenumsthemen für Dienstag (
{
str
(
d
)
}
20:00)
'
msg
[
'
From
'
]
=
'
{{noreply_email_user}}
'
msg
[
'
To
'
]
=
'
intern@warpzone.ms
'
msg
[
'
Date
'
]
=
formatdate
(
localtime
=
True
)
msg
.
set_content
(
mail
)
server
=
smtplib
.
SMTP
(
'
{{smtp_host}}
'
,
{{
smtp_port
}})
server
.
starttls
()
server
.
login
(
"
{{noreply_email_user}}
"
,
"
{{noreply_email_pass}}
"
)
server
.
send_message
(
msg
)
server
.
quit
()
return
True
if
not
topic_replaced
and
"
====== 1.
"
in
old_line
:
new_content
.
append
(
f
"
====== 1.5
{
label
}
======
"
)
topic_replaced
=
True
with
open
(
"
/srv/dokuwiki/data/data/pages/intern/diskussionsthemen.txt
"
,
"
w
"
)
as
fp
:
fp
.
write
(
"
\n
"
.
join
(
new_content
))
success
=
False
try
:
success
=
do_work
()
wait_until_unlocked
()
topics
=
get_topics
()
if
(
len
(
topics
)
!=
0
):
# calculate date of next tuesday
date
=
datetime
.
date
.
today
()
while
date
.
strftime
(
'
%a
'
)
!=
'
Tue
'
:
date
+=
datetime
.
timedelta
(
1
)
success
=
send_mail
(
topics
,
date
)
label
=
f
"
Diskussionsthemen für
{
date
}
"
if
success
:
label
+=
f
"
(bereits eingeladen)
"
else
:
label
+=
f
"
(Einladung fehlgeschlagen)
"
success
=
update_page
(
label
)
else
:
success
=
True
except
:
success
=
False
raise
finally
:
requests
.
get
(
"
{{ healthchecks_url }}
"
if
success
else
"
{{ healthchecks_url }}
"
+
"
/fail
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment