.conf wird korrekt angelegt
This commit is contained in:
parent
cac14d6a93
commit
17fcd4fc49
1 changed files with 18 additions and 7 deletions
|
|
@ -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.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue