-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.py
61 lines (52 loc) · 1.53 KB
/
config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: config.py
# Author: Yuxin Wu <[email protected]>
import os
import json
from functools import lru_cache
@lru_cache()
def get_config(fname=None):
FNAME = 'config.json'
def get_fname():
if os.path.isfile(FNAME):
return FNAME
fname = os.path.join(os.path.dirname(__file__), FNAME)
if os.path.isfile(fname):
return fname
raise RuntimeError("Cannot find config.json file!")
if fname is None:
fname = get_fname()
with open(fname) as f:
obj = json.load(f)
return obj
@lru_cache()
def get_house_ids(fname=None):
FNAME = 'all_house_ids.json'
def get_fname():
if os.path.isfile(FNAME):
return FNAME
fname = os.path.join(os.path.dirname(__file__), FNAME)
if os.path.isfile(fname):
return fname
raise RuntimeError("Cannot find all_house_ids.json file!")
if fname is None:
fname = get_fname()
with open(fname) as f:
obj = json.load(f)
return obj
@lru_cache()
def get_house_targets(fname=None):
FNAME = 'all_house_targets.json'
def get_fname():
if os.path.isfile(FNAME):
return FNAME
fname = os.path.join(os.path.dirname(__file__), FNAME)
if os.path.isfile(fname):
return fname
raise RuntimeError("Cannot find all_house_targets.json file!")
if fname is None:
fname = get_fname()
with open(fname) as f:
obj = json.load(f)
return obj