This commit is contained in:
2020-12-23 18:00:19 +01:00
parent 7670e448b2
commit 8ecae62901
3 changed files with 20 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ import sys, os
import pypandoc
import argparse
import quopri
import requests
import json
from pprint import pprint
CONFIG_FILE = "generator.conf"
@@ -42,8 +44,9 @@ def get_body_text(msg):
class Top:
def __init__(self, title=None, sender=None, body=None, protostub=None, message=None):
if message:
self.title = decode_header(message["Subject"])[6:]
self.title = decode_header(message["Subject"][6:])
real_name, address = email.utils.parseaddr(message["From"])
real_name = decode_header(real_name)
self.sender = real_name or address
payload = get_body_text(message)
self.body = str(payload.rpartition("\n--")[0] if "\n--" in payload else payload)
@@ -125,10 +128,12 @@ if __name__ == "__main__":
parser.add_argument("--config", default=CONFIG_FILE)
mode = parser.add_mutually_exclusive_group(required=True)
mode.add_argument("--invite", action="store_true")
mode.add_argument("--mm-invite", action="store_true")
mode.add_argument("--presentation", action="store_true")
mode.add_argument("--protocol", action="store_true")
parser.add_argument("--debug", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--write-mbox", action="store_true")
parser.add_argument("--send-mm", action="store_true")
args = parser.parse_args()
config = yaml.full_load(open(args.config))
@@ -137,6 +142,8 @@ if __name__ == "__main__":
template_file = config["invite_template_file"]
elif args.presentation:
template_file = config["presentation_template_file"]
elif args.mm_invite:
template_file = config["mminvite_template_file"]
elif args.protocol:
template_file = config["protocol_template_file"]
else:
@@ -204,5 +211,9 @@ if __name__ == "__main__":
mbox.add(msg)
mbox.close()
print(mbox)
elif args.send_mm:
headers = {'Content-Type': 'application/json',}
values = json.dumps({ "text": template.render(context), "username": "test"})
response = requests.post(config["mm_url"], headers=headers, data=values)
else:
print(template.render(context))