test
This commit is contained in:
parent
0b697d851f
commit
b9640987d4
@ -10,6 +10,7 @@ from .m3u import M3U
|
|||||||
from .epg import EPG
|
from .epg import EPG
|
||||||
from .tuners import Tuners
|
from .tuners import Tuners
|
||||||
from .debug import Debug_JSON
|
from .debug import Debug_JSON
|
||||||
|
from .tools import API_Tools
|
||||||
|
|
||||||
from .images import Images
|
from .images import Images
|
||||||
|
|
||||||
@ -30,5 +31,6 @@ class fHDHR_API():
|
|||||||
self.epg = EPG(fhdhr)
|
self.epg = EPG(fhdhr)
|
||||||
self.tuners = Tuners(fhdhr)
|
self.tuners = Tuners(fhdhr)
|
||||||
self.debug = Debug_JSON(fhdhr)
|
self.debug = Debug_JSON(fhdhr)
|
||||||
|
self.tools = API_Tools(fhdhr)
|
||||||
|
|
||||||
self.images = Images(fhdhr)
|
self.images = Images(fhdhr)
|
||||||
|
|||||||
47
fHDHR_web/api/tools.py
Normal file
47
fHDHR_web/api/tools.py
Normal file
@ -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
|
||||||
@ -10,6 +10,7 @@ from .version_html import Version_HTML
|
|||||||
from .diagnostics_html import Diagnostics_HTML
|
from .diagnostics_html import Diagnostics_HTML
|
||||||
from .settings_html import Settings_HTML
|
from .settings_html import Settings_HTML
|
||||||
from .channels_editor import Channels_Editor_HTML
|
from .channels_editor import Channels_Editor_HTML
|
||||||
|
from .tools import Tools_HTML
|
||||||
|
|
||||||
|
|
||||||
class fHDHR_Pages():
|
class fHDHR_Pages():
|
||||||
@ -27,3 +28,4 @@ class fHDHR_Pages():
|
|||||||
self.version_html = Version_HTML(fhdhr)
|
self.version_html = Version_HTML(fhdhr)
|
||||||
self.diagnostics_html = Diagnostics_HTML(fhdhr)
|
self.diagnostics_html = Diagnostics_HTML(fhdhr)
|
||||||
self.settings_html = Settings_HTML(fhdhr)
|
self.settings_html = Settings_HTML(fhdhr)
|
||||||
|
self.tools = Tools_HTML(fhdhr)
|
||||||
|
|||||||
16
fHDHR_web/pages/tools.py
Normal file
16
fHDHR_web/pages/tools.py
Normal file
@ -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)
|
||||||
12
fHDHR_web/templates/tools.html
Normal file
12
fHDHR_web/templates/tools.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h4 style="text-align: center;">{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Tools</h4>
|
||||||
|
|
||||||
|
<form method="post" action="/api/tools?method=prettyjson&redirect=%2Ftools">
|
||||||
|
<a data-th="URL"><input type="text" name="url" value=""></a>
|
||||||
|
<a data-th="Convert Json url to tabbbed"><input type="submit" value="Convert Json url to tabbbed"></a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue
Block a user