Configuration file support

master
informatic 2013-09-02 23:17:07 +02:00
parent a013922f4a
commit 2a6c158f7c
2 changed files with 7 additions and 7 deletions

3
main.cfg.dist Normal file
View File

@ -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

View File

@ -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()