Ross Mountjoy 62191b21b8 ##### Updated to version 0.6!
> Version 0.6 brings DashMachine one big step forward to being a finished product by adding a gui to edit the various settings in the config.ini.

**Changelog**
- improvements to /home including 'pinned' cards, multi-select tag filtering, 'action providers' allowing you to do web searches from the searchbar
- rebuilt sidenav with list view, mirroring filter/search/collapse state of the homepage
- /settings and /home now on same route
- dynamic reloading of settings (no more page reloads)
- dedicated config.ini editor slide-out
- settings editor slide-out
- card editor slide-out
- better access group control
- dedicated documentation pages
- improved documentation
- new system for automatically generating documentation for platforms
- ability to load custom platforms
- added an 'on_starup' method for platforms allowing for registering api routes. (example coming soon)
2020-05-07 09:27:18 -04:00

90 lines
2.9 KiB
Python

import requests
from flask import render_template_string
class Platform:
def docs(self):
documentation = {
"name": "curl",
"author": "buoyantotter",
"author_url": "https://github.com/buoyantotter",
"version": 1.0,
"description": "Curl an URL and show result",
"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
```
""",
"returns": "`value_template` as rendered string",
"returns_json_keys": ["value"],
"variables": [
{
"variable": "[variable_name]",
"description": "Name for the data source.",
"default": "",
"options": ".ini header",
},
{
"variable": "platform",
"description": "Name of the platform.",
"default": "curl",
"options": "curl",
},
{
"variable": "resource",
"description": "Url to curl",
"default": "https://example.com",
"options": "url",
},
{
"variable": "value_template",
"description": "Jinja template for how the returned data from api is displayed.",
"default": "{{value}}",
"options": "jinja template",
},
{
"variable": "response_type",
"description": "Response type. Use json if response is a JSON.",
"default": "plain",
"options": "plain,json",
},
],
}
return documentation
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)