diff --git a/server.py b/server.py new file mode 100644 index 0000000..0b5af28 --- /dev/null +++ b/server.py @@ -0,0 +1,16 @@ +from flask import Flask, request, jsonify + +app = Flask(__name__) + +@app.route('/music/set', methods=['POST']) +def set_content(): + global cache + cache = request.get_json() + return jsonify({'message': 'Content set successfully'}) + +@app.route('/music/display', methods=['GET']) +def display_content(): + return jsonify(cache) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/test.py b/test.py index 68e182c..fd8de6c 100644 --- a/test.py +++ b/test.py @@ -27,6 +27,16 @@ def get_track_extras(song, artist, album): return (artwork_url, itunes_url, artist_url) +url = "http://127.0.0.1:5000" +headers = {'Content-Type': 'application/json'} + +def post(currentsong): + data = json.dumps(currentsong) + r = requests.post(url+'/music/set', data=data, headers=headers) + + r = requests.get(url+'/music/display') + print(r.text) + currentsong = json.loads(str(get_current_song()).replace("'''", '"')) if currentsong['status'] == 'playing': @@ -34,12 +44,13 @@ if currentsong['status'] == 'playing': currentsong['artwork_url'] = artwork_url currentsong['itunes_url'] = itunes_url currentsong['artist_url'] = artist_url - - pprint(currentsong) + post(currentsong) elif currentsong['status'] == 'not playing': print('not playing') + post({'status' : 'not playing'}) elif currentsong['status'] == 'not running': print('not running') + post({'status' : 'not running'}) else: pass diff --git a/testpost.py b/testpost.py new file mode 100644 index 0000000..5b1a102 --- /dev/null +++ b/testpost.py @@ -0,0 +1,17 @@ +import requests +import json + +url = "http://127.0.0.1:5000" + +payload = { + 'key1': 'value1', + 'key2': 'value2' +} + +json_payload = json.dumps(payload) + +headers = {'Content-Type': 'application/json'} + +r = requests.post(url+'/set', data=json_payload, headers=headers) +r = requests.get(url+'/display') +print(r.text) \ No newline at end of file