Formatting broke the merge

This commit is contained in:
2017-02-09 00:50:26 +01:00

82
app.py
View File

@@ -8,7 +8,7 @@ from json import loads, dumps
import requests
from werkzeug.security import generate_password_hash, \
check_password_hash
check_password_hash
from status.diskusage import diskUsage
from status.uptime import timeSinceBoot
@@ -22,9 +22,9 @@ auth = HTTPBasicAuth()
# Hardcoded users, the password is hashed with salt used by wekzeug
users = {
"kevin": "9f6c79bbb3b8bbc4e6aab32314afaf3c812df66b",
"apollo": "BerryTree",
"test": "test"
"kevin": "9f6c79bbb3b8bbc4e6aab32314afaf3c812df66b",
"apollo": "BerryTree",
"test": "test"
}
tmdbBaseURL = "https://api.themoviedb.org/3/"
@@ -37,8 +37,8 @@ tmdbBaseURL = "https://api.themoviedb.org/3/"
# # Costum function for hashing and verifying the sent password.
# # TODO Read if ok to send in cleartext like this if use https
# def verifyHash(pw):
# pw_hash = generate_password_hash(pw)
# return check_password_hash(pw_hash, pw)
# pw_hash = generate_password_hash(pw)
# return check_password_hash(pw_hash, pw)
# Flask function for getting password matching username sent by http request
@auth.get_password
@@ -51,7 +51,7 @@ def get_pw(username):
# to not match.
@auth.error_handler
def unauthorized():
return make_response(jsonify({'error': 'Unauthorized access'}), 401)
return make_response(jsonify({'error': 'Unauthorized access'}), 401)
# This would be replaced with a database, but single process and thread
# can use local data like this for simplicity.
@@ -60,10 +60,10 @@ def unauthorized():
# Want all return data to be JSON so create custom error response
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
return make_response(jsonify({'error': 'Not found'}), 404)
@app.errorhandler(400)
def bad_request(error):
return make_response(jsonify({'error': 'Bad request'}), 400)
return make_response(jsonify({'error': 'Bad request'}), 400)
# --- Apollo Activity --- #
@@ -71,28 +71,28 @@ def bad_request(error):
@app.route('/api/v1/disks', methods=['GET'])
@auth.login_required
def get_diskUsage():
returningDiskUsage = diskUsage(request.args.get('dir'))
if returningDiskUsage != None:
return jsonify(returningDiskUsage)
else:
abort(404)
returningDiskUsage = diskUsage(request.args.get('dir'))
if returningDiskUsage != None:
return jsonify(returningDiskUsage)
else:
abort(404)
@app.route('/api/v1/uptimes', methods=['GET'])
@auth.login_required
def get_uptimes():
try:
return jsonify({ 'uptime': timeSinceBoot() })
except:
abort(404)
try:
return jsonify({ 'uptime': timeSinceBoot() })
except:
abort(404)
@app.route('/api/v1/temps', methods=['GET'])
def get_temps():
cpuTemp = getCpuTemp()
if cpuTemp != None:
return jsonify( {"Avg cpu temp": cpuTemp} )
else:
return jsonify( {"Error":"Temp reading not supported for host machine."} )
cpuTemp = getCpuTemp()
if cpuTemp != None:
return jsonify( {"Avg cpu temp": cpuTemp} )
else:
return jsonify( {"Error":"Temp reading not supported for host machine."} )
# TODO PLEX
# Search, watching, +photo
@@ -108,44 +108,44 @@ def get_movieRequest():
@app.route('/api/v1/plex/movies', methods=['GET'])
@auth.login_required
def getPlexMovies():
title = request.args.get('title')
title = request.args.get('title')
movieInfo = getSpecificMovieInfo(title)
if movieInfo != None:
return jsonify(movieInfo)
movieInfo = getSpecificMovieInfo(title)
if movieInfo != None:
return jsonify(movieInfo)
abort(500)
abort(500)
@app.route('/api/v1/plex/watchings', methods=['GET'])
@auth.login_required
def getPlexWatchings():
r = requests.get('http://10.0.0.41:32400/status/sessions')
r = requests.get('http://10.0.0.41:32400/status/sessions')
return r.text
movieInfo = getSpecificMovieInfo(title)
if movieInfo != None:
return jsonify(movieInfo)
return r.text
movieInfo = getSpecificMovieInfo(title)
if movieInfo != None:
return jsonify(movieInfo)
@app.route('/api/v1/uptimes/duration', methods=['GET'])
@auth.login_required
def get_uptimesDuration():
up = uptime.uptime()
return jsonify( {'Duration': up.duration} )
up = uptime.uptime()
return jsonify( {'Duration': up.duration} )
@app.route('/api/v1/uptimes/users', methods=['GET'])
@auth.login_required
def get_uptimesUsers():
up = uptime.uptime()
return jsonify( {'Users': up.users} )
up = uptime.uptime()
return jsonify( {'Users': up.users} )
@app.route('/api/v1/uptimes/load', methods=['GET'])
@auth.login_required
def get_uptimesLoad():
up = uptime.uptime()
return jsonify( {'Load': up.load} )
up = uptime.uptime()
return jsonify( {'Load': up.load} )
if __name__ == '__main__':
app.run(host="0.0.0.0",port=63590, debug=True)
app.run(host="0.0.0.0",port=63590, debug=True)