Use script path to determine conf & template path [task 1, status:done]

This commit is contained in:
2020-07-04 17:33:48 +02:00
parent bd5bf11661
commit 11834803c8

View File

@@ -1,3 +1,4 @@
import os
from configparser import ConfigParser from configparser import ConfigParser
import json import json
import smtplib import smtplib
@@ -15,8 +16,13 @@ RECEIVER_EMAIL = 'd@e.f'
def main(): def main():
global SMTP_PORT, SMTP_SERVER, SENDER_EMAIL, RECEIVER_EMAIL 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 = ConfigParser()
parser.read('conf.ini') parser.read(conf_file)
SMTP_PORT = parser.get('config', 'smtp_port') SMTP_PORT = parser.get('config', 'smtp_port')
SMTP_SERVER = parser.get('config', 'smtp_server') SMTP_SERVER = parser.get('config', 'smtp_server')
@@ -71,7 +77,7 @@ def main():
# print(content) # print(content)
with open('template.html', 'r') as f_template: with open(template_file, 'r') as f_template:
template = f_template.read() template = f_template.read()
send_mail(template.replace('{{content}}', content)) send_mail(template.replace('{{content}}', content))