diff --git a/fHDHR_web/api/__init__.py b/fHDHR_web/api/__init__.py index 58d17fe..f91a5b4 100644 --- a/fHDHR_web/api/__init__.py +++ b/fHDHR_web/api/__init__.py @@ -10,6 +10,7 @@ from .m3u import M3U from .epg import EPG from .tuners import Tuners from .debug import Debug_JSON +from .tools import API_Tools from .images import Images @@ -30,5 +31,6 @@ class fHDHR_API(): self.epg = EPG(fhdhr) self.tuners = Tuners(fhdhr) self.debug = Debug_JSON(fhdhr) + self.tools = API_Tools(fhdhr) self.images = Images(fhdhr) diff --git a/fHDHR_web/api/tools.py b/fHDHR_web/api/tools.py new file mode 100644 index 0000000..89af64f --- /dev/null +++ b/fHDHR_web/api/tools.py @@ -0,0 +1,47 @@ +from flask import Response, request, redirect +import urllib.parse +import json + + +class API_Tools(): + endpoints = ["/api/tools"] + endpoint_name = "api_tools" + endpoint_methods = ["GET", "POST"] + + def __init__(self, fhdhr): + self.fhdhr = fhdhr + + def __call__(self, *args): + return self.get(*args) + + def get(self, *args): + + method = request.args.get('method', default="get", type=str) + + redirect_url = request.args.get('redirect', default=None, type=str) + + if method == "prettyjson": + + dirty_json_url = request.form.get('url', None) + + try: + json_url_req = self.fhdhr.web.session.get(dirty_json_url) + json_url_req.raise_for_status() + json_resp = json_url_req.json() + except self.fhdhr.web.exceptions.HTTPError as err: + self.fhdhr.logger.error('Error while getting stations: %s' % err) + json_resp = {"error": 'Error while getting stations: %s' % err} + + return_json = json.dumps(json_resp, indent=4) + + return Response(status=200, + response=return_json, + mimetype='application/json') + + else: + return "%s Invalid Method" % method + + if redirect_url: + return redirect(redirect_url + "?retmessage=" + urllib.parse.quote("%s Success" % method)) + else: + return "%s Success" % method diff --git a/fHDHR_web/pages/__init__.py b/fHDHR_web/pages/__init__.py index f0c4acd..b73e6c5 100644 --- a/fHDHR_web/pages/__init__.py +++ b/fHDHR_web/pages/__init__.py @@ -10,6 +10,7 @@ from .version_html import Version_HTML from .diagnostics_html import Diagnostics_HTML from .settings_html import Settings_HTML from .channels_editor import Channels_Editor_HTML +from .tools import Tools_HTML class fHDHR_Pages(): @@ -27,3 +28,4 @@ class fHDHR_Pages(): self.version_html = Version_HTML(fhdhr) self.diagnostics_html = Diagnostics_HTML(fhdhr) self.settings_html = Settings_HTML(fhdhr) + self.tools = Tools_HTML(fhdhr) diff --git a/fHDHR_web/pages/tools.py b/fHDHR_web/pages/tools.py new file mode 100644 index 0000000..94c26aa --- /dev/null +++ b/fHDHR_web/pages/tools.py @@ -0,0 +1,16 @@ +from flask import request, render_template + + +class Tools_HTML(): + endpoints = ["/tools", "/tools.html"] + endpoint_name = "tools_html" + + def __init__(self, fhdhr): + self.fhdhr = fhdhr + + def __call__(self, *args): + return self.get(*args) + + def get(self, *args): + + return render_template('tools.html', request=request, fhdhr=self.fhdhr) diff --git a/fHDHR_web/templates/tools.html b/fHDHR_web/templates/tools.html new file mode 100644 index 0000000..2366785 --- /dev/null +++ b/fHDHR_web/templates/tools.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block content %} + +

{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Tools

+ +
+ + +
+ +{% endblock %}