64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
import argparse
|
|
import base64
|
|
from jinja2 import Environment, FileSystemLoader
|
|
import os
|
|
|
|
def encode_file(path, mime_type):
|
|
"""Liest eine Datei ein und gibt eine data-uri zurück."""
|
|
with open(path, 'rb') as f:
|
|
data = f.read()
|
|
return f"data:{mime_type};base64,{base64.b64encode(data).decode('utf-8')}"
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Generiere eine HTML-E-Mail-Signatur für das CyMaIS Projekt"
|
|
)
|
|
parser.add_argument('-n', '--name', required=True, help="Vollständiger Name")
|
|
parser.add_argument('-P', '--position', required=True, help="Position / Titel")
|
|
parser.add_argument('-t', '--phone', required=True, help="Telefonnummer")
|
|
parser.add_argument('-u', '--username', required=True, help="Allgemeiner Nutzername für E-Mail, WordPress, Mastodon, etc.")
|
|
parser.add_argument('-l', '--linkedin', required=True, help="LinkedIn-Nutzername (ohne URL)")
|
|
parser.add_argument('-a', '--address', default='', help="Anschrift (optional)")
|
|
parser.add_argument('-o', '--output', default='signature.html', help="Zieldatei für die generierte Signatur")
|
|
args = parser.parse_args()
|
|
|
|
# Basis-Kontext
|
|
context = {
|
|
'name': args.name,
|
|
'position': args.position,
|
|
'company': 'CyMaIS Projekt',
|
|
'address': args.address,
|
|
'phone': args.phone,
|
|
'email': f"{args.username}@cymais.cloud",
|
|
'website_url': 'https://www.cymais.cloud/',
|
|
'socials': {
|
|
'LinkedIn': f'https://www.linkedin.com/in/{args.linkedin}',
|
|
'WordPress': 'https://www.cymais.cloud/',
|
|
'Mastodon': f'https://mastodon.social/@{args.username}',
|
|
'PeerTube': f'https://peertube.video/channel/{args.username}',
|
|
'PixelFed': f'https://pixelfed.social/@{args.username}',
|
|
}
|
|
}
|
|
|
|
# Pfad zum Template-Verzeichnis
|
|
env = Environment(loader=FileSystemLoader(os.path.dirname(__file__)))
|
|
template = env.get_template('signature_template.j2')
|
|
|
|
# Logo und Icons einbetten
|
|
context['logo'] = encode_file(os.path.join(os.path.dirname(__file__), 'logo.png'), 'image/png')
|
|
context['icons'] = {}
|
|
for name, url in context['socials'].items():
|
|
filename = name.lower() + ('.png' if name == 'LinkedIn' else '.svg')
|
|
mime = 'image/png' if name == 'LinkedIn' else 'image/svg+xml'
|
|
context['icons'][name] = encode_file(os.path.join(os.path.dirname(__file__), filename), mime)
|
|
|
|
# Rendern und speichern
|
|
output = template.render(**context)
|
|
with open(args.output, 'w', encoding='utf-8') as f:
|
|
f.write(output)
|
|
|
|
print(f"Signatur erfolgreich generiert: {args.output}")
|
|
|
|
if __name__ == '__main__':
|
|
main() |