.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 telebot
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
if os.path.isfile('Postankündigung.conf') is False:
|
conf = os.path.basename(sys.argv[0])
|
||||||
print('"Postankündigung.conf" scheint es nicht zu geben.')
|
|
||||||
print('Ich lege eine neue Datei "Postankündigung.conf" an.')
|
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": "",
|
passw={"mail_pass": "","mail_user": "",
|
||||||
"mail_host": "",
|
"mail_host": "",
|
||||||
"mail_folder": "",
|
"mail_folder": "",
|
||||||
"Chat_ID": "","TOKEN": ""
|
"Chat_ID": "","TOKEN": ""
|
||||||
}
|
}
|
||||||
print(str(passw)+ ' bitte entsprechend befüllen.')
|
print(str(conf)+ ' bitte entsprechend befüllen.')
|
||||||
with open('Postankündigung.conf', 'w') as fp:
|
with open(conf, 'w') as fp:
|
||||||
json.dump(passw, fp, sort_keys=True, indent=4)
|
json.dump(passw, fp, sort_keys=True, indent=4)
|
||||||
quit()
|
quit()
|
||||||
else:
|
else:
|
||||||
with open('Postankündigung.conf') as file:
|
with open(conf) as file:
|
||||||
passw = json.load(file)
|
passw = json.load(file)
|
||||||
|
|
||||||
TOKEN = passw['TOKEN']
|
TOKEN = passw['TOKEN']
|
||||||
|
|
@ -28,7 +40,6 @@ folder = passw['mail_folder']
|
||||||
|
|
||||||
tb = telebot.TeleBot(TOKEN)
|
tb = telebot.TeleBot(TOKEN)
|
||||||
|
|
||||||
|
|
||||||
with MailBox(host).login(username, password, folder) as mailbox:
|
with MailBox(host).login(username, password, folder) as mailbox:
|
||||||
anzahl = len(mailbox.numbers(criteria='UNSEEN'))
|
anzahl = len(mailbox.numbers(criteria='UNSEEN'))
|
||||||
ankuendigung = 'Heute befinden sich ' + str(anzahl) + ' Sendungen auf dem Weg in die Hintergasse.'
|
ankuendigung = 'Heute befinden sich ' + str(anzahl) + ' Sendungen auf dem Weg in die Hintergasse.'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue