mirror of
				https://github.com/KevinMidboe/Node-Com-Handler.git
				synced 2025-10-29 17:50:27 +00:00 
			
		
		
		
	Changed how much logic is in app.py
This commit is contained in:
		
							
								
								
									
										49
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								app.py
									
									
									
									
									
								
							| @@ -12,10 +12,11 @@ from werkzeug.security import generate_password_hash, \ | |||||||
|  |  | ||||||
| from status.diskusage import diskUsage | from status.diskusage import diskUsage | ||||||
| from status.uptime import timeSinceBoot | from status.uptime import timeSinceBoot | ||||||
|  | from status.load import load | ||||||
| from status.cpuTemp import getCpuTemp | from status.cpuTemp import getCpuTemp | ||||||
| from plex.tmdb import tmdbSearch |  | ||||||
|  |  | ||||||
| from plex.plexMovies import getSpecificMovieInfo | from plex.tmdb import tmdbSearch | ||||||
|  | from plex.plexSearch import plexSearch | ||||||
|  |  | ||||||
| app = Flask(__name__, static_url_path = "") | app = Flask(__name__, static_url_path = "") | ||||||
| auth = HTTPBasicAuth() | auth = HTTPBasicAuth() | ||||||
| @@ -67,32 +68,24 @@ def bad_request(error): | |||||||
|  |  | ||||||
|  |  | ||||||
| # --- Apollo Activity --- # | # --- Apollo Activity --- # | ||||||
|  | @app.route('/api/v1/load', methods=['GET']) | ||||||
|  | def get_load(): | ||||||
|  |     return jsonify(load()) | ||||||
|  |  | ||||||
|  |  | ||||||
| @app.route('/api/v1/disks', methods=['GET']) | @app.route('/api/v1/disks', methods=['GET']) | ||||||
| @auth.login_required |  | ||||||
| def get_diskUsage(): | def get_diskUsage(): | ||||||
|     returningDiskUsage = diskUsage(request.args.get('dir')) |     return jsonify(diskUsage(request.args.get('dir'))) | ||||||
|     if returningDiskUsage != None: |  | ||||||
|         return jsonify(returningDiskUsage) |  | ||||||
|     else: |  | ||||||
|         abort(404) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @app.route('/api/v1/uptimes', methods=['GET']) | @app.route('/api/v1/uptimes', methods=['GET']) | ||||||
| @auth.login_required |  | ||||||
| def get_uptimes(): | def get_uptimes(): | ||||||
|     try: |  | ||||||
|     return jsonify({ 'uptime': timeSinceBoot() }) |     return jsonify({ 'uptime': timeSinceBoot() }) | ||||||
|     except: |  | ||||||
|         abort(404) |  | ||||||
|  |  | ||||||
| @app.route('/api/v1/temps', methods=['GET']) | @app.route('/api/v1/temps', methods=['GET']) | ||||||
| def get_temps(): | def get_temps(): | ||||||
|     cpuTemp = getCpuTemp() |     return  jsonify(getCpuTemp()) | ||||||
|     if cpuTemp != None: |  | ||||||
|         return jsonify( {"Avg cpu temp": cpuTemp} ) |  | ||||||
|     else: |  | ||||||
|         return jsonify( {"Error":"Temp reading not supported for host machine."} ) |  | ||||||
|  |  | ||||||
| # TODO PLEX | # TODO PLEX | ||||||
| # Search, watching, +photo | # Search, watching, +photo | ||||||
| @@ -106,12 +99,12 @@ def get_movieRequest(): | |||||||
| 	else: return jsonify({ "Error": "Query not defined." }) | 	else: return jsonify({ "Error": "Query not defined." }) | ||||||
|  |  | ||||||
| @app.route('/api/v1/plex/movies', methods=['GET']) | @app.route('/api/v1/plex/movies', methods=['GET']) | ||||||
| @auth.login_required |  | ||||||
| def getPlexMovies(): | def getPlexMovies(): | ||||||
|     title = request.args.get('title') |     title = request.args.get('title') | ||||||
|  |  | ||||||
|     movieInfo = getSpecificMovieInfo(title) |     movieInfo = plexSearch(title) | ||||||
|     if movieInfo != None: |     if movieInfo != None: | ||||||
|  |         print(movieInfo) | ||||||
|         return jsonify(movieInfo) |         return jsonify(movieInfo) | ||||||
|  |  | ||||||
|     abort(500) |     abort(500) | ||||||
| @@ -127,24 +120,6 @@ def getPlexWatchings(): | |||||||
|         return jsonify(movieInfo) |         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} ) |  | ||||||
|  |  | ||||||
| @app.route('/api/v1/uptimes/users', methods=['GET']) |  | ||||||
| @auth.login_required |  | ||||||
| def get_uptimesUsers(): |  | ||||||
|     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} ) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | 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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user