added config minutes setting

This commit is contained in:
Nicholas St. Germain 2018-11-28 23:47:04 -06:00
parent b7605ebbcc
commit a5f138785d
5 changed files with 27 additions and 15 deletions

View file

@ -40,9 +40,12 @@ class SonarrServer(NamedTuple):
url: str = None url: str = None
api_key: str = None api_key: str = None
verify_ssl: bool = False verify_ssl: bool = False
missing_days: int = None missing_days: int = 0
future_days: int = None missing_days_run_minutes: int = 30
future_days: int = 0
future_days_run_minutes: int = 30
queue: bool = False queue: bool = False
queue_run_minutes: int = 1
class Server(NamedTuple): class Server(NamedTuple):
id: int = None id: int = None

View file

@ -61,9 +61,13 @@ class INIParser(object):
queue = self.config.getboolean(sonarr_section, 'queue') queue = self.config.getboolean(sonarr_section, 'queue')
missing_days = self.config.getint(sonarr_section, 'missing_days') missing_days = self.config.getint(sonarr_section, 'missing_days')
future_days = self.config.getint(sonarr_section, 'future_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, self.sonarr_servers.append(SonarrServer(server_id, scheme + url, apikey, verify_ssl, missing_days,
missing_days, future_days, queue)) missing_days_run_minutes, future_days,
future_days_run_minutes, queue, queue_run_minutes))
# Parse Radarr options # Parse Radarr options
try: try:

View file

@ -31,7 +31,8 @@ class SonarrAPI(object):
missing = [] missing = []
headers = {'X-Api-Key': server.api_key} 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 # Iteratively create a list of TVShow Objects from response json
tv_shows = [TVShow(**show) for show in get] tv_shows = [TVShow(**show) for show in get]
@ -74,7 +75,8 @@ class SonarrAPI(object):
headers = {'X-Api-Key': server.api_key} headers = {'X-Api-Key': server.api_key}
params = {'start': self.today, 'end': future} 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] tv_shows = [TVShow(**show) for show in get]
for show in tv_shows: for show in tv_shows:
@ -104,7 +106,7 @@ class SonarrAPI(object):
self.influx_push(influx_payload) self.influx_push(influx_payload)
@logging @logging
def get_queue(self): def get_queue(self, notimplemented):
influx_payload = [] influx_payload = []
endpoint = '/api/queue' endpoint = '/api/queue'
@ -112,7 +114,7 @@ class SonarrAPI(object):
queue = [] queue = []
headers = {'X-Api-Key': server.api_key} 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] download_queue = [Queue(**show) for show in get]
for show in download_queue: for show in download_queue:

View file

@ -24,8 +24,11 @@ apikey = xxxxxxxxxxxxxxxx
ssl = false ssl = false
verify_ssl = true verify_ssl = true
missing_days = 7 missing_days = 7
missing_days_run_minutes = 30
future_days = 1 future_days = 1
future_days_run_minutes = 30
queue = true queue = true
queue_run_minutes = 1
[sonarr-2] [sonarr-2]
url = sonarr2.domain.tld url = sonarr2.domain.tld

View file

@ -6,9 +6,8 @@ from Varken.iniparser import INIParser
from Varken.sonarr import SonarrAPI from Varken.sonarr import SonarrAPI
def threaded(job): def threaded(job, days=None):
print('test') thread = threading.Thread(target=job, args=([days]))
thread = threading.Thread(target=job)
thread.start() thread.start()
if __name__ == "__main__": if __name__ == "__main__":
@ -19,12 +18,13 @@ if __name__ == "__main__":
for server in CONFIG.sonarr_servers: for server in CONFIG.sonarr_servers:
if server.queue: 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: 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: 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: while True:
schedule.run_pending() schedule.run_pending()