diff --git a/main.cfg.dist b/main.cfg.dist new file mode 100644 index 0000000..5d3176a --- /dev/null +++ b/main.cfg.dist @@ -0,0 +1,3 @@ +AT_API_URL = "https://at.hackerspace.pl/api" +OPEN_DAY_WEEKDAY = 4 # Thursday (according to %w of http://docs.python.org/2/library/time.html#time.strftime) +OPEN_DAY_BEGIN_HOUR = 18 diff --git a/spaceapi.py b/spaceapi.py index 46042a8..7f4b00a 100644 --- a/spaceapi.py +++ b/spaceapi.py @@ -10,11 +10,8 @@ import urllib2 import traceback import time -AT_API_URL = "https://at.hackerspace.pl/api" -OPEN_DAY_WEEKDAY = 4 # Thursday (according to %w of http://docs.python.org/2/library/time.html#time.strftime) -OPEN_DAY_BEGIN_HOUR = 18 - app = Flask(__name__) +app.config.from_pyfile('main.cfg') @app.route('/') def api_index(): @@ -23,7 +20,7 @@ def api_index(): open_day = False try: - at_request = urllib2.Request(AT_API_URL) + at_request = urllib2.Request(app.config['AT_API_URL']) at_request.add_header('User-Agent', 'HSWAWSpaceAPI/1.0 +https://spaceapi.hackerspace.pl') at_response = urllib2.urlopen(at_request).read() at_object = json.loads(at_response) @@ -32,8 +29,8 @@ def api_index(): people_now_present['value'] = len(at_object['users']) people_now_present['names'] = list(user['login'] for user in at_object['users']) - open_day = space_open and int(time.strftime("%w")) == OPEN_DAY_WEEKDAY \ - and int(time.strftime("%H")) >= OPEN_DAY_BEGIN_HOUR + open_day = space_open and int(time.strftime("%w")) == app.config['OPEN_DAY_WEEKDAY'] \ + and int(time.strftime("%H")) >= app.config['OPEN_DAY_BEGIN_HOUR'] except: traceback.print_exc()