This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathshackapi.py
More file actions
executable file
·78 lines (68 loc) · 2.11 KB
/
Copy pathshackapi.py
File metadata and controls
executable file
·78 lines (68 loc) · 2.11 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask, jsonify
import json
import requests
app = Flask(__name__)
mpd_room_to_port = {'lounge': 6600,
'semi': 6601,
'elab': 6602,
'kueche': 6603,
'crafting': 6604,
'fablab': 6605,
'workshop': 6606}
@app.route('/')
def hello():
return "Hello World!"
@app.route('/portal/status')
def portal_status():
response = requests.get('http://portal.shack:8088/status').json()
return jsonify(response)
@app.route('/mpd/<string:room>/status')
def mpd_status(room):
if not room in mpd_room_to_port:
return jsonify({'error': 'unkown room'})
from mpd import MPDClient
client = MPDClient()
client.connect('mpd.shack', mpd_room_to_port[room])
state = client.status()['state']
return jsonify({'status': state})
@app.route('/mpd/<string:room>/toggle')
def mpd_toggle(room):
if not room in mpd_room_to_port:
return jsonify({'error': 'unkown room'})
from mpd import MPDClient
client = MPDClient()
client.connect('mpd.shack', mpd_room_to_port[room])
state = client.status()['state']
if state == 'play':
client.pause()
new_state = 'pause'
else:
client.play()
new_state = 'play'
client.close()
client.disconnect()
response = jsonify({'old_state': state,
'new_state': new_state})
return response
@app.route('/mpd/<string:room>/song')
def mpd_song(room):
if not room in mpd_room_to_port:
return jsonify({'error': 'unkown room'})
from mpd import MPDClient
client = MPDClient()
client.connect('mpd.shack', mpd_room_to_port[room])
song = client.currentsong()
client.close()
client.disconnect()
return jsonify(song)
@app.route('/trash/dates')
def trash_date():
resp = {}
r = requests.get("https://meinsack.click/v1/70327/Ulmer%20Stra%C3%9Fe/")
resp['next_yellow'] = r.json().get('dates')[0]
return jsonify(resp)
if __name__ == "__main__":
app.debug = True
app.run(host='::')