-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_config.py
More file actions
27 lines (25 loc) · 774 Bytes
/
read_config.py
File metadata and controls
27 lines (25 loc) · 774 Bytes
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
# -*- coding: utf-8 -*-
import configparser
import os.path
def read_config(config_path):
arrs = {'key': [], 'proxy': ''}
if config_path is None:
print("error in config path,is None")
return
if not os.path.exists(config_path):
print("error in config path,is not exists")
return
cf = configparser.ConfigParser()
cf.read(config_path)
sections = cf.sections()
if 'key' in sections:
keys = cf.options('key')
for key in keys:
if key != '':
arrs['key'].append(cf.get('key', key))
if 'proxy' in sections:
proxy_list = cf.options('proxy')
for key in proxy_list:
if key != '':
arrs['proxy'] = cf.get('proxy', key)
return arrs