mirror of
https://github.com/NohamR/AM-Exporter.git
synced 2026-05-25 04:07:11 +00:00
server implementation
This commit is contained in:
16
server.py
Normal file
16
server.py
Normal file
@@ -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)
|
||||
15
test.py
15
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
|
||||
|
||||
|
||||
17
testpost.py
Normal file
17
testpost.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user