Added support for Outlook

outlook_support
a.jurcenko 2023-08-15 11:39:24 +02:00
parent c7b89efa40
commit f2811ba495
3 changed files with 67 additions and 8 deletions

54
app.py
View File

@ -1,7 +1,9 @@
import lxml.etree
from lxml import etree
import os
import json
import datetime as dt
import lxml.etree
from lxml import etree
import win32com.client as win32
from aktion_status import AktionsStatus
@ -14,10 +16,15 @@ class App:
self._prefix = "\t"
self._delimiter = "\t"
self._convert_date = False
self._send_outlook = False
self._attach_file = False
self._text = None
self._print_console = True
self._read_config()
def read_xml(self, path, hide_empty=True):
self._text = ""
with open(path, encoding="utf-8") as xml_file:
head = xml_file.readline()
xml = xml_file.read()
@ -26,6 +33,15 @@ class App:
for elem in data.getchildren():
self._read_element(elem, hide_empty=hide_empty)
if self._send_outlook:
outlook = win32.gencache.EnsureDispatch('Outlook.Application')
new_mail = outlook.CreateItem(0)
new_mail.Subject = "Test"
new_mail.Body = self._text
if self._attach_file:
abs_path = os.path.abspath(path)
new_mail.Attachments.Add(Source=abs_path)
new_mail.Display(True)
def _read_element(self, element, sign="", hide_empty=True):
element_text = element.text
@ -37,23 +53,38 @@ class App:
pass
elif element.tag.find("AKTION") > -1:
num = int(element_text)
print(sign, self._clean_xmlns(element.tag), self._delimiter, AktionsStatus.get_status(num), end=self._endline)
self._print(sign, self._clean_xmlns(element.tag), self._delimiter, AktionsStatus.get_status(num), end=self._endline)
elif self._convert_date and element.tag.find("NKZEIT") > -1:
time = dt.datetime.strptime(element_text, "%H%M%S")
uhrzeit = time.strftime("%H:%M:%S")
print(sign, self._clean_xmlns(element.tag), self._delimiter, uhrzeit,
self._print(sign, self._clean_xmlns(element.tag), self._delimiter, uhrzeit,
end=self._endline)
elif self._convert_date and element.tag.find("NKDATUM") > -1:
date = dt.datetime.strptime(element_text, "%Y%m%d")
datum = date.strftime("%d.%m.%Y")
print(sign, self._clean_xmlns(element.tag), self._delimiter, datum,
self._print(sign, self._clean_xmlns(element.tag), self._delimiter, datum,
end=self._endline)
elif self._convert_date and element.tag.find("AUFTRDATUM") > -1:
date = dt.datetime.strptime(element_text, "%Y%m%d")
datum = date.strftime("%d.%m.%Y")
self._print(sign, self._clean_xmlns(element.tag), self._delimiter, datum,
end=self._endline)
else:
print(sign, self._clean_xmlns(element.tag), self._delimiter, element.text if element.text else "", end=self._endline)
self._print(sign, self._clean_xmlns(element.tag), self._delimiter, element.text if element.text else "", end=self._endline)
if len(element.getchildren()) > 0:
for el in element.getchildren():
self._read_element(el, sign + self._prefix)
def _print(self, *args, **kwargs):
if self._send_outlook:
line = ""
for arg in args:
line += str(arg)
line = line + self._endline
self._text += line
if self._print_console:
print(*args, **kwargs)
def _clean_xmlns(self, tag_text):
if tag_text and tag_text.startswith("{"):
return tag_text.split("}")[1]
@ -77,4 +108,15 @@ class App:
convert = json_raw.get('convert-date')
if convert:
self._convert_date = convert
console = json_raw.get('print-console')
if console is not None:
self._print_console = console
if json_raw.get("outlook"):
outlook = json_raw.get('outlook')
send = outlook.get('send')
attach = outlook.get('attach-file')
if send:
self._send_outlook = send
if attach:
self._attach_file = attach

View File

@ -1,10 +1,27 @@
{
"path": null,
"hide-elements": [
"PO", "TO", "AK", "NKNR", "NVE", "GGVS", "POFD", "ABR", "LM", "INFO", "RSTK", "FD", "ADR-VU"
"PO", "TO", "ADR-AG", "ADR-FZ",
"ADR-UNT","AK", "NKNR",
"NVE", "GGVS", "POFD",
"ABR", "LM", "INFO", "RSTK", "FD",
"ADR-VU", "SD", "ADR-BST", "ADR-EST", "ADR-ABS",
"ADR-EMP", "FZGD"
],
"delimiter": ": ",
"endline": "\n",
"prefix": "\t",
"convert-date": true
"convert-date": true,
"outlook": {
"send": false,
"attach-file": false,
"conditions": {
"CarloIn": {
"to": [
]
}
}
},
"print-console": true
}

Binary file not shown.