From 11834803c822efab5aaac8ddbd45aa572a90fb31 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Sat, 4 Jul 2020 17:33:48 +0200 Subject: [PATCH] Use script path to determine conf & template path [task 1, status:done] --- notifier.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/notifier.py b/notifier.py index 0fe20fd..0dce3b1 100644 --- a/notifier.py +++ b/notifier.py @@ -1,3 +1,4 @@ +import os from configparser import ConfigParser import json import smtplib @@ -15,8 +16,13 @@ RECEIVER_EMAIL = 'd@e.f' def main(): global SMTP_PORT, SMTP_SERVER, SENDER_EMAIL, RECEIVER_EMAIL + + script_dir = os.path.dirname(__file__) + conf_file = os.path.join(script_dir, 'conf.ini') + template_file = os.path.join(script_dir, 'template.html') + parser = ConfigParser() - parser.read('conf.ini') + parser.read(conf_file) SMTP_PORT = parser.get('config', 'smtp_port') SMTP_SERVER = parser.get('config', 'smtp_server') @@ -71,7 +77,7 @@ def main(): # print(content) - with open('template.html', 'r') as f_template: + with open(template_file, 'r') as f_template: template = f_template.read() send_mail(template.replace('{{content}}', content))