From a5f138785dabd419e2b10931b4e0c24e77619ee3 Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Wed, 28 Nov 2018 23:47:04 -0600 Subject: [PATCH] added config minutes setting --- Varken/helpers.py | 7 +++++-- Varken/iniparser.py | 8 ++++++-- Varken/sonarr.py | 10 ++++++---- Varken/varken.example.ini | 3 +++ Varken/varken.py | 14 +++++++------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Varken/helpers.py b/Varken/helpers.py index 5d9e456..2551928 100644 --- a/Varken/helpers.py +++ b/Varken/helpers.py @@ -40,9 +40,12 @@ class SonarrServer(NamedTuple): url: str = None api_key: str = None verify_ssl: bool = False - missing_days: int = None - future_days: int = None + missing_days: int = 0 + missing_days_run_minutes: int = 30 + future_days: int = 0 + future_days_run_minutes: int = 30 queue: bool = False + queue_run_minutes: int = 1 class Server(NamedTuple): id: int = None diff --git a/Varken/iniparser.py b/Varken/iniparser.py index 233db54..0ea8098 100644 --- a/Varken/iniparser.py +++ b/Varken/iniparser.py @@ -61,9 +61,13 @@ class INIParser(object): queue = self.config.getboolean(sonarr_section, 'queue') missing_days = self.config.getint(sonarr_section, 'missing_days') future_days = self.config.getint(sonarr_section, 'future_days') + missing_days_run_minutes = self.config.getint(sonarr_section, 'missing_days_run_minutes') + future_days_run_minutes = self.config.getint(sonarr_section, 'future_days_run_minutes') + queue_run_minutes = self.config.getint(sonarr_section, 'queue_run_minutes') - self.sonarr_servers.append(SonarrServer(server_id, scheme + url, apikey, verify_ssl, - missing_days, future_days, queue)) + self.sonarr_servers.append(SonarrServer(server_id, scheme + url, apikey, verify_ssl, missing_days, + missing_days_run_minutes, future_days, + future_days_run_minutes, queue, queue_run_minutes)) # Parse Radarr options try: diff --git a/Varken/sonarr.py b/Varken/sonarr.py index 21cf87c..c93a067 100644 --- a/Varken/sonarr.py +++ b/Varken/sonarr.py @@ -31,7 +31,8 @@ class SonarrAPI(object): missing = [] headers = {'X-Api-Key': server.api_key} - get = self.session.get(server.url + endpoint, params=params, headers=headers).json() + get = self.session.get(server.url + endpoint, params=params, headers=headers, + verify=server.verify_ssl).json() # Iteratively create a list of TVShow Objects from response json tv_shows = [TVShow(**show) for show in get] @@ -74,7 +75,8 @@ class SonarrAPI(object): headers = {'X-Api-Key': server.api_key} params = {'start': self.today, 'end': future} - get = self.session.get(server.url + endpoint, params=params, headers=headers).json() + get = self.session.get(server.url + endpoint, params=params, headers=headers, + verify=server.verify_ssl).json() tv_shows = [TVShow(**show) for show in get] for show in tv_shows: @@ -104,7 +106,7 @@ class SonarrAPI(object): self.influx_push(influx_payload) @logging - def get_queue(self): + def get_queue(self, notimplemented): influx_payload = [] endpoint = '/api/queue' @@ -112,7 +114,7 @@ class SonarrAPI(object): queue = [] headers = {'X-Api-Key': server.api_key} - get = self.session.get(server.url + endpoint, headers=headers).json() + get = self.session.get(server.url + endpoint, headers=headers, verify=server.verify_ssl).json() download_queue = [Queue(**show) for show in get] for show in download_queue: diff --git a/Varken/varken.example.ini b/Varken/varken.example.ini index 39a6073..e3022ed 100644 --- a/Varken/varken.example.ini +++ b/Varken/varken.example.ini @@ -24,8 +24,11 @@ apikey = xxxxxxxxxxxxxxxx ssl = false verify_ssl = true missing_days = 7 +missing_days_run_minutes = 30 future_days = 1 +future_days_run_minutes = 30 queue = true +queue_run_minutes = 1 [sonarr-2] url = sonarr2.domain.tld diff --git a/Varken/varken.py b/Varken/varken.py index 0af850d..2212e48 100644 --- a/Varken/varken.py +++ b/Varken/varken.py @@ -6,9 +6,8 @@ from Varken.iniparser import INIParser from Varken.sonarr import SonarrAPI -def threaded(job): - print('test') - thread = threading.Thread(target=job) +def threaded(job, days=None): + thread = threading.Thread(target=job, args=([days])) thread.start() if __name__ == "__main__": @@ -19,12 +18,13 @@ if __name__ == "__main__": for server in CONFIG.sonarr_servers: if server.queue: - schedule.every(1).minutes.do(threaded, SONARR.get_queue) + schedule.every(server.queue_run_minutes).minutes.do(threaded, SONARR.get_queue) if server.missing_days > 0: - schedule.every(30).minutes.do(threaded, SONARR.get_missing, server.missing_days) + schedule.every(server.missing_days_run_minutes).minutes.do(threaded, SONARR.get_missing, + server.missing_days) if server.future_days > 0: - schedule.every(30).minutes.do(threaded, SONARR.get_future, server.future_days) - + schedule.every(server.future_days_run_minutes).minutes.do(threaded, SONARR.get_future, + server.future_days) while True: schedule.run_pending()