From 17fcd4fc49976e0620625dd5f0ae544f37e4b62b Mon Sep 17 00:00:00 2001 From: hubobel Date: Fri, 25 Feb 2022 11:20:50 +0100 Subject: [PATCH] .conf wird korrekt angelegt --- Postankündigung.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Postankündigung.py b/Postankündigung.py index fea0ef8..a96dbf9 100644 --- a/Postankündigung.py +++ b/Postankündigung.py @@ -2,21 +2,33 @@ from imap_tools import MailBox import telebot import os import json +import sys -if os.path.isfile('Postankündigung.conf') is False: - print('"Postankündigung.conf" scheint es nicht zu geben.') - print('Ich lege eine neue Datei "Postankündigung.conf" an.') +conf = os.path.basename(sys.argv[0]) + +conf = conf.replace(".py", ".conf") + + + +absFilePath = os.path.abspath(__file__) +path, filename = os.path.split(absFilePath) +conf = path + '/' +conf + + +if os.path.isfile(conf) is False: + print(conf + ' scheint es nicht zu geben.') + print('Ich lege eine neue Datei '+ conf + ' an.') passw={"mail_pass": "","mail_user": "", "mail_host": "", "mail_folder": "", "Chat_ID": "","TOKEN": "" } - print(str(passw)+ ' bitte entsprechend befüllen.') - with open('Postankündigung.conf', 'w') as fp: + print(str(conf)+ ' bitte entsprechend befüllen.') + with open(conf, 'w') as fp: json.dump(passw, fp, sort_keys=True, indent=4) quit() else: - with open('Postankündigung.conf') as file: + with open(conf) as file: passw = json.load(file) TOKEN = passw['TOKEN'] @@ -28,7 +40,6 @@ folder = passw['mail_folder'] tb = telebot.TeleBot(TOKEN) - with MailBox(host).login(username, password, folder) as mailbox: anzahl = len(mailbox.numbers(criteria='UNSEEN')) ankuendigung = 'Heute befinden sich ' + str(anzahl) + ' Sendungen auf dem Weg in die Hintergasse.'