-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_parser.py
35 lines (27 loc) · 1.07 KB
/
config_parser.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
from configparser import ConfigParser
class CustomConfigParser():
def __init__(self, ini_file='./torrentscraper.ini'):
self.ini_file = ini_file
self.config_parser = ConfigParser()
self.config_parser.read(self.ini_file)
def get_section_map(self, section):
dict1 = {}
options = self.config_parser.options(section)
for option in options:
try:
dict1[option] = self.config_parser.get(section, option)
if dict1[option] == -1:
print("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
# print(self.get_section_map('WebScrapers'))
def set_section_key(self, section, key, value):
self.config_parser.set(section, key, value)
try:
# Writing the configuration file
with open(self.ini_file, 'w+') as configfile:
self.config_parser.write(configfile)
except Exception as err:
print('error:',err)