spaceapi support
parent
745889e920
commit
3a8c5412fa
|
@ -6,3 +6,8 @@ FEEDS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
MAX_ENTRIES = 10
|
MAX_ENTRIES = 10
|
||||||
|
|
||||||
|
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
|
||||||
|
|
75
main.py
75
main.py
|
@ -4,8 +4,9 @@ import feedparser
|
||||||
import requests
|
import requests
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
from flask import Flask, render_template, request, flash, session, abort
|
import json
|
||||||
from time import mktime
|
from flask import Flask, render_template, request, flash, session, abort, jsonify
|
||||||
|
from time import mktime, strftime
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
app = Flask('main')
|
app = Flask('main')
|
||||||
|
@ -81,6 +82,76 @@ def about_en():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
parse_subscribe_requests()
|
parse_subscribe_requests()
|
||||||
return render_template('about_en.html', entries=pull_feed_entries())
|
return render_template('about_en.html', entries=pull_feed_entries())
|
||||||
|
|
||||||
|
@app.route('/spaceapi')
|
||||||
|
def spaceapi():
|
||||||
|
space_open = None
|
||||||
|
people_now_present = {'value': 0}
|
||||||
|
open_day = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
at_response = requests.get(app.config['AT_API_URL'], headers={
|
||||||
|
'User-Agent': 'HSWAWSpaceAPI/1.0 +https://hackerspace.pl/spaceapi'
|
||||||
|
})
|
||||||
|
at_object = json.loads(at_response.content)
|
||||||
|
|
||||||
|
space_open = len(at_object['users']) > 0
|
||||||
|
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(strftime("%w")) == app.config['OPEN_DAY_WEEKDAY'] \
|
||||||
|
and int(strftime("%H")) >= app.config['OPEN_DAY_BEGIN_HOUR']
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"api": "0.13",
|
||||||
|
"space": "Warsaw Hackerspace",
|
||||||
|
"logo": "https://static.hackerspace.pl/img/syrenka-black.png",
|
||||||
|
"url": "https://hackerspace.pl",
|
||||||
|
"location": {
|
||||||
|
"lat": 52.2462275,
|
||||||
|
"lon": 21.003067,
|
||||||
|
"address": "ul. Długa 44/50, 00-241 Warszawa, Poland",
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"open": space_open,
|
||||||
|
"message": "open for public" if open_day else "members only",
|
||||||
|
# @TODO: customized *space* logo
|
||||||
|
"icon": {
|
||||||
|
"open": "https://static.hackerspace.pl/img/status-open-small.png",
|
||||||
|
"closed": "https://static.hackerspace.pl/img/status-closed-small.png",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"contact": {
|
||||||
|
"irc": "irc://chat.freenode.net/#hackerspace-pl",
|
||||||
|
"twitter": "@hackerspacepl",
|
||||||
|
"facebook": "hackerspacepl",
|
||||||
|
"ml": "waw@lists.hackerspace.pl",
|
||||||
|
},
|
||||||
|
"issue_report_channels": [
|
||||||
|
"ml"
|
||||||
|
],
|
||||||
|
"projects": [
|
||||||
|
"https://wiki.hackerspace.pl/projects",
|
||||||
|
],
|
||||||
|
"feeds": {
|
||||||
|
"blog": {"type": "atom", "url": "https://blog.hackerspace.pl/feed/atom/"},
|
||||||
|
"calendar": {"type": "ical", "url": "https://www.google.com/calendar/ical/hackerspacewaw%40gmail.com/public/basic.ics"},
|
||||||
|
"wiki": {"type": "rss", "url": "https://wiki.hackerspace.pl/feed.php"},
|
||||||
|
},
|
||||||
|
"sensors": {
|
||||||
|
"people_now_present": [people_now_present]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# SpaceAPI version <0.13 compliance
|
||||||
|
result['open'] = result['state']['open']
|
||||||
|
result['icon'] = result['state']['icon']
|
||||||
|
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def csrf_protect():
|
def csrf_protect():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
|
Loading…
Reference in New Issue