Documentation/formatting

This commit is contained in:
cpp 2020-06-15 12:26:42 +02:00
parent eda546cf6d
commit 4965d55e86

View file

@ -1,13 +1,21 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# assemble the undead #### Assemble the Undead #####
# #
# This is a script that serves the purpose of creating a wikipage and # This is a script that serves the purpose of creating a wikipage and
# send out a mail, when there are issues in redmine with a certain # send out a mail, when there are issues in redmine with a certain
# status. It's supposed to be running as a crownjob. # status. It's supposed to be running as a crownjob.
# #
# Copyright 2020 <cpp@zom.bi> #### Arguments: #####
#
# --nomail do not send a mail
# --nowiki don't create a wiki page
# --verbose, -v output everything
# --quiet, -q only print errors
#
#
#### Copyright 2020 <cpp@zom.bi> #####
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -35,7 +43,7 @@ redmine_api_key = ''
## Mediawiki config ## Mediawiki config
mediawiki_url = 'https://w.zom.bi' mediawiki_url = 'https://w.zom.bi'
# those should be Bot credentials, that can be created on Special:BotPasswords # should be Bot credentials, that can be created on Special:BotPasswords
mediawiki_username = 'Assemblybot@assemblybot' mediawiki_username = 'Assemblybot@assemblybot'
mediawiki_botpassword='' mediawiki_botpassword=''
@ -43,7 +51,7 @@ mediawiki_botpassword=''
smtp_host = 'mail.zom.bi' smtp_host = 'mail.zom.bi'
smtp_port = 465 smtp_port = 465
smtp_from = 'assembly_noreply@zom.bi' smtp_from = 'assembly_noreply@zom.bi'
smtp_to = [''] smtp_recipients = [['']]
smtp_user = 'assemblybot' smtp_user = 'assemblybot'
smtp_password = '' smtp_password = ''
mail_subject = '☣ The undead assemble' mail_subject = '☣ The undead assemble'
@ -52,7 +60,6 @@ issues that require a decision from an assembly. You'll find a list \
of said issues at the end of this mail. If you wonna know more about \ of said issues at the end of this mail. If you wonna know more about \
those topics, please head to our issue tracker at https://tickets.zom.bi\ those topics, please head to our issue tracker at https://tickets.zom.bi\
\n----\n\n\n" \n----\n\n\n"
mail_footer = "\n----\n beep, boop. I'm a bot.\n If you wonna\ mail_footer = "\n----\n beep, boop. I'm a bot.\n If you wonna\
complain about me, write a mail to cpp or create a ticket at https://tickets.zom.bi" complain about me, write a mail to cpp or create a ticket at https://tickets.zom.bi"
@ -67,7 +74,8 @@ def main(args):
# do nothing, if there are no issues requiring an assembly. # do nothing, if there are no issues requiring an assembly.
log(1,"No issue requires an assembly.\n exiting.") log(1,"No issue requires an assembly.\n exiting.")
return 0 return 0
mediawiki_page = {'title': 'Zombi:Assembly '+assembly_date, 'content':'{{plenum|Datum=' + assembly_date + '}}'} mediawiki_page = {'title': 'Zombi:Assembly '+assembly_date,\
'content':'{{plenum|Datum=' + assembly_date + '}}'}
mediawiki_page['content'] = '=Issues from redmine that require an assembly=\n' mediawiki_page['content'] = '=Issues from redmine that require an assembly=\n'
for issue in issues: for issue in issues:
# Append every issue to the page content # Append every issue to the page content
@ -86,18 +94,24 @@ def main(args):
if '--no-mail' in args: if '--no-mail' in args:
log(1,"'--no-mail' argument given, so no mails have been sent.") log(1,"'--no-mail' argument given, so no mails have been sent.")
else: else:
smtp_send()
return 0
def smtp_send()
smtp_server = smtplib.SMTP_SSL(host=smtp_host,port=smtp_port) smtp_server = smtplib.SMTP_SSL(host=smtp_host,port=smtp_port)
if loglevel == 2: if loglevel == 2:
smtp_server.set_debuglevel(1) smtp_server.set_debuglevel(1)
smtp_server.connect(host=smtp_host) smtp_server.connect(host=smtp_host)
smtp_server.login(user=smtp_user,password=smtp_password) smtp_server.login(user=smtp_user,password=smtp_password)
mail_message = MIMEText(mail_header + mediawiki_page['content'] + mail_footer) mail_message = MIMEText(mail_header + \
mediawiki_page['content'] + mail_footer)
mail_message['Subject'] = mail_subject mail_message['Subject'] = mail_subject
mail_message['From'] = smtp_from mail_message['From'] = smtp_from
mail_message['To'] = None for recipient in smtp_recipients:
smtp_server.sendmail(from_addr=smtp_from,to_addrs=smtp_to,msg=mail_message.as_string()) mail_message['To'] = recipient
smtp_server.sendmail(from_addr=smtp_from,\
to_addrs=recipient,msg=mail_message.as_string())
smtp_server.quit() smtp_server.quit()
return 0
def redmine_request(path): def redmine_request(path):
request = requests.get(redmine_url + path, request = requests.get(redmine_url + path,
@ -109,7 +123,8 @@ def redmine_request(path):
def redmine_get_requires_assembly_id(): def redmine_get_requires_assembly_id():
data = redmine_request('/issue_statuses.json') data = redmine_request('/issue_statuses.json')
requires_assembly = next(filter(lambda x: x['name'] == 'Requires Assembly',data['issue_statuses']))['id'] requires_assembly = next(filter(lambda x: x['name'] == \
'Requires Assembly',data['issue_statuses']))['id']
return requires_assembly return requires_assembly
def redmine_get_issues(state): def redmine_get_issues(state):
@ -140,7 +155,8 @@ def mediawiki_create(s,page):
t_request = s.post(mediawiki_url + t_request = s.post(mediawiki_url +
'/api.php?action=query&format=json&meta=tokens') '/api.php?action=query&format=json&meta=tokens')
token = t_request.json()["query"]["tokens"]["csrftoken"] token = t_request.json()["query"]["tokens"]["csrftoken"]
response = s.post(mediawiki_url + '/api.php?action=edit&format=json' + '&title=' + page['title'] + '&text=', response = s.post(mediawiki_url + '/api.php?action=edit&format=json' \
+ '&title=' + page['title'] + '&text=',
data = { data = {
'token': token, 'token': token,
'text' : page['content'] 'text' : page['content']