-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDConfig.py
38 lines (31 loc) · 1.14 KB
/
DDConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os,io,json,stat
import logging
log = logging.getLogger(__name__)
class DDConfig:
filename='dd.json'
baseurl='https://www.dailydose.de/private-kleinanzeigen'
def __init__(self):
self.config={}
if os.path.isfile(self.filename):
# simply read the config file
self.config = json.load(open(self.filename))
else:
# generate a config file interactively
self.config=self.__generateConfig()
self.config['baseurl']=self.baseurl
def __generateConfig(self):
username = input('dailydose Login: ')
password = input('dailydose Passwort: ')
path = input('Verzeichnis mit Anzeigen: ')
self.config['username']=username
self.config['password']=password
self.config['anzeigenpath']=path
umask = 0o066 # create file with 0600 -rw------- only owner can read+write
umask_original = os.umask(umask)
with io.open(self.filename, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.config,indent=4, ensure_ascii=False))
os.umask(umask_original)
log.info("Konfiguration in "+self.filename+" gespeichert.")
return self.config
def __getitem__(self, key):
return self.config[key]