diff --git a/dashmachine/platform/curl.py b/dashmachine/platform/curl.py new file mode 100644 index 0000000..b137c9c --- /dev/null +++ b/dashmachine/platform/curl.py @@ -0,0 +1,66 @@ +""" + +##### curl +Curl an URL and show result +```ini +[variable_name] +platform = curl +resource = https://example.com +value_template = {{value}} +response_type = json +``` +> **Returns:** `value_template` as rendered string + +| Variable | Required | Description | Options | +|-----------------|----------|-----------------------------------------------------------------|-------------------| +| [variable_name] | Yes | Name for the data source. | [variable_name] | +| plaform | Yes | Name of the platform. | curl | +| resource | Yes | Url to curl | url | +| value_template | Yes | Jinja template for how the returned data from api is displayed. | jinja template | +| response_type | No | Response type. Use json if response is a JSON. Default is plain.| plain,json | + +> **Working example:** +>```ini +>[test] +>platform = curl +>resource = https://api.myip.com +>value_template = My IP: {{value.ip}} +response_type = json +> +>[MyIp.com] +>prefix = https:// +>url = myip.com +>icon = static/images/apps/default.png +>description = Link to myip.com +>open_in = new_tab +>data_sources = test +>``` +""" + +import requests +from flask import render_template_string + +class Platform: + def __init__(self, *args, **kwargs): + # parse the user's options from the config entries + for key, value in kwargs.items(): + self.__dict__[key] = value + + # set defaults for omitted options + if not hasattr(self, "response_type"): + self.response_type = "plain" + + def process(self): + if self.response_type.lower() == "json": + try: + value = requests.get(self.resource).json() + print(value) + except Exception as e: + value = f"{e}" + else: + try: + value = requests.get(self.resource) + except Exception as e: + value = f"{e}" + + return render_template_string(self.value_template, value=value) \ No newline at end of file diff --git a/dashmachine/static/images/apps/dokuwiki.png b/dashmachine/static/images/apps/dokuwiki.png new file mode 100644 index 0000000..617ef7c Binary files /dev/null and b/dashmachine/static/images/apps/dokuwiki.png differ diff --git a/dashmachine/static/images/apps/duplicati.png b/dashmachine/static/images/apps/duplicati.png new file mode 100644 index 0000000..55d5b3a Binary files /dev/null and b/dashmachine/static/images/apps/duplicati.png differ diff --git a/dashmachine/static/images/apps/firefly_iii.png b/dashmachine/static/images/apps/firefly_iii.png new file mode 100644 index 0000000..ba1cf6b Binary files /dev/null and b/dashmachine/static/images/apps/firefly_iii.png differ diff --git a/dashmachine/static/images/apps/nodered.png b/dashmachine/static/images/apps/nodered.png new file mode 100644 index 0000000..89f6811 Binary files /dev/null and b/dashmachine/static/images/apps/nodered.png differ diff --git a/dashmachine/static/images/apps/openmediavault.png b/dashmachine/static/images/apps/openmediavault.png new file mode 100644 index 0000000..f3ea670 Binary files /dev/null and b/dashmachine/static/images/apps/openmediavault.png differ diff --git a/template_apps/DokuWiki.ini b/template_apps/DokuWiki.ini new file mode 100644 index 0000000..19cf825 --- /dev/null +++ b/template_apps/DokuWiki.ini @@ -0,0 +1,6 @@ +[DokuWiki] +prefix = https:// +url = your-website.com +icon = static/images/apps/dokuwiki.png +description = DokuWiki is a simple to use and highly versatile Open Source wiki software that does not require a database. +open_in = this_tab \ No newline at end of file diff --git a/template_apps/Duplicati.ini b/template_apps/Duplicati.ini new file mode 100644 index 0000000..8ce584b --- /dev/null +++ b/template_apps/Duplicati.ini @@ -0,0 +1,6 @@ +[Duplicati] +prefix = https:// +url = your-website.com +icon = static/images/apps/duplicati.png +description = Free backup software to store encrypted backups online +open_in = this_tab \ No newline at end of file diff --git a/template_apps/Firefly-III.ini b/template_apps/Firefly-III.ini new file mode 100644 index 0000000..ac1d753 --- /dev/null +++ b/template_apps/Firefly-III.ini @@ -0,0 +1,6 @@ +[Firefly-III] +prefix = https:// +url = your-website.com +icon = static/images/apps/firefly_iii.png +description = Firefly III is a self-hosted financial manager. It can help you keep track of expenses, income, budgets and everything in between. +open_in = this_tab diff --git a/template_apps/Node-RED.ini b/template_apps/Node-RED.ini new file mode 100644 index 0000000..250e541 --- /dev/null +++ b/template_apps/Node-RED.ini @@ -0,0 +1,6 @@ +[Node-RED] +prefix = https:// +url = your-website.com +icon = static/images/apps/nodered.png +description = Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. +open_in = this_tab diff --git a/template_apps/OpenMediaVault.ini b/template_apps/OpenMediaVault.ini new file mode 100644 index 0000000..3ac6257 --- /dev/null +++ b/template_apps/OpenMediaVault.ini @@ -0,0 +1,6 @@ +[OpenMediaVault] +prefix = https:// +url = your-website.com +icon = static/images/apps/openmediavault.png +description = OpenMediaVault is the next generation network attached storage (NAS) solution based on Debian Linux. +open_in = this_tab \ No newline at end of file