From 9846f3d1b8348d272d3c12aa2bc6865e32c8f71d Mon Sep 17 00:00:00 2001 From: romaine murray Date: Wed, 8 Apr 2020 10:50:33 -0500 Subject: [PATCH] added support for sabnzbd --- .gitignore | 1 + dashmachine/platform/sabnzbd.py | 109 +++++++++++++++++++++ dashmachine/static/images/apps/sabnzbd.png | Bin 0 -> 2094 bytes template_apps/Sabnzbd.ini | 7 ++ 4 files changed, 117 insertions(+) create mode 100644 dashmachine/platform/sabnzbd.py create mode 100644 dashmachine/static/images/apps/sabnzbd.png create mode 100644 template_apps/Sabnzbd.ini diff --git a/.gitignore b/.gitignore index 14a1b59..fe6184a 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,7 @@ scheduler.db scheduler.db .idea/ +.vscode/ dashmachine/user_data/ dashmachine/static/images/icons diff --git a/dashmachine/platform/sabnzbd.py b/dashmachine/platform/sabnzbd.py new file mode 100644 index 0000000..fc6881f --- /dev/null +++ b/dashmachine/platform/sabnzbd.py @@ -0,0 +1,109 @@ +""" + +##### SABnzbd +Display information from the SABnzbd API +```ini +[variable_name] +platform = sabnzbd +host = localhost +port = 8080 +api_key = my_api_key +value_template = {{ value_template }} +``` +> **Returns:** `value_template` as rendered string + +| Variable | Required | Description | Options | +|-----------------|----------|-----------------------------------------------------------------|-------------------| +| [variable_name] | Yes | Name for the data source. | [variable_name] | +| platform | Yes | Name of the platform. | sabnzbd | +| host | Yes | Host of Sabnzbd | host | +| port | Yes | Port of Sabnzbd | port | +| api_key | Yes | Api key for the Sabnzbd | api key | +| value_template | Yes | Jinja template for how the returned data from API is displayed. | jinja template | + +
+###### **Available fields for value_template** + +* status +* no_of_slots +* speed +* size +* disk_free +* eta +* mb_left +* time_left + +> **Working example:** +>```ini +> [sabnzbd-data] +> platform = sabnzbd +> host = 192.168.1.32 +> port = 8080 +> api_key = {{ API Key}} +> value_template = Status:{{status}}
⬇ {{speed}}
Size: {{size}}
+> +> [Sabnzbd] +> prefix = http:// +> url = 192.168.1.32:8080 +> icon = static/images/apps/sabnzbd.png +> description = SABnzbd is a multi-platform binary newsgroup downloader. The program works in the background and simplifies the downloading verifying and extracting of files from Usenet. +> open_in = iframe +> data_sources = sabnzbd-data +>``` +""" + +import json +from flask import render_template_string +import requests + + + +class Sabnzbd(object): + # Takes the ip address of Sabnzbd + def __init__(self,ip_address,port,api_key): + self.ip_address = ip_address + self.port = port + self.api_key = api_key + + + def refresh(self): + if self.api_key != None: + rawdata = requests.get( + "http://" + + self.ip_address + + ":" + + self.port + + "/api?" + + "apikey=" + + self.api_key + + "&mode=queue" + + "&output=json" + ).json() + + queue = rawdata["queue"] + self.status = queue["status"] + self.no_of_slots = queue["noofslots_total"] + self.speed = queue["speed"] + self.size = queue["size"] + self.disk_free = queue["diskspace1_norm"] + self.eta = queue["eta"] + self.mb_left = queue["mbleft"] + self.time_left = queue["timeleft"] + + + + + +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 + self.sabnzbd = Sabnzbd(self.host, self.port, self.api_key) + + def process(self): + self.sabnzbd.refresh() + value_template = render_template_string( + self.value_template, **self.sabnzbd.__dict__ + ) + return value_template \ No newline at end of file diff --git a/dashmachine/static/images/apps/sabnzbd.png b/dashmachine/static/images/apps/sabnzbd.png new file mode 100644 index 0000000000000000000000000000000000000000..c264ee51ce8b9761a93b6a2177d22332844b854d GIT binary patch literal 2094 zcmV+}2+{Y6P)$ zYiv}<6~}+GPcPWJ$=Vb`P_V)N(n?L;3d}6YG)<{!ir`yY-bQ?= z;=y#ndH*SzzF|L z%5pGTCqS1u=9f|iA{U9)vypWImV*rRtn$IeZ(yAOfV2^QOArM@cP#FlJGEUl=@CPR&AZy6LF^feYRK{^A{J}{A0FslAnwtYD9SwhQk^lju zrXZVf%;cN_vMDu&gHh&e1Y|RiUZ89sgp!zp;SWv|0J)-QAs`n-VrB@K|ExWq4V;#N zP#LE3@HcfY-~)aDY?-I+hRTLctIDvd#<^XhCs+G>vXv6>JkU|*dkORc-5%gYU|*%a zBq}+7NXDQlh$DrOSMc#C2|lqk@P&apu)Y?aeH?WMTnaks61p4=8ThO1$-pbPcx95op)_8vmtZh7r-_t0PB1i}FE1U&m=2wRY`+XYSc!@#Ezk{KJ-n}DfA<%7R; z5q|wAru`K#8lBPP9$+m61QcQ=@GqAB9iO64dwaVqhT-918488W*!pAPqzfY;0IUM& z?(U|!xw#lg^CA+7uzUAzqR}YfaF{b^&QMcRW69R7TesM^uY8Rb3Wd0Q`7)_g>D=sg zyE%969OuuU2dFLlu8;spuEc3=ZDsT3&6b>=oSekxQ*Y7v{eC(+I#{t{g(X|TU~t|x zUayy}Ter^JuCK4p_;bdhQZz@EV{<;Z-R`oV&A^TyvysUZU&&3qBsDNFz=aDJ5M}oJ znx>&?8la-#x-o&!TA> zH8nMKb#>wQ`)xV7kSHnvBaK;srfK!*q3ZSsr-*{{39NdKG{pM~-m(_;Jg& z?4VErDd2Xc9ZMA!m7*}hbQ@>=Qc9A^=@SsMwhAL41Z)G?wQCm*4Gm>i?)LU}Qv=OL zOG^u0uNQ!(rY6gFd_EuBw{K@+Vgi8L+S++~%*5<90DwJv_R!YWX4$Dq(B0kbh@DU< zL{CqT<^IchFJK&X0cFc?v$hH`yABWl6B85p71}IDM@RG0(RH2C(b2LQr5qxWNdE71 zI&Ik}Pz72JGng#=5JVk_tPO|5mTLiB*BKcZLDzL$E*EumbtT!K52;j&v9U2gX+0bc zTe1UcUlNPO0Nw%~E!FNhK*O0+oPRrHX9|^_oUk&*tO}X0|j1m)jPSIhhEy*nmvAWuU5=aB2_#9cLc1FgU(OsA*+au-eBz!u;ys8>}US}G_0 Y4>19`^;`;7R{#J207*qoM6N<$f+v^O_5c6? literal 0 HcmV?d00001 diff --git a/template_apps/Sabnzbd.ini b/template_apps/Sabnzbd.ini new file mode 100644 index 0000000..24c560c --- /dev/null +++ b/template_apps/Sabnzbd.ini @@ -0,0 +1,7 @@ +[Sabnzbd] +prefix = https:// +url = your-website.com +icon = static/images/apps/sabnzbd.png +sidebar_icon = static/images/apps/sabnzbd.png +description = SABnzbd is a multi-platform binary newsgroup downloader. The program works in the background and simplifies the downloading verifying and extracting of files from Usenet. +open_in = this_tab \ No newline at end of file