Clean up some formatting

This commit is contained in:
samwiseg0 2018-11-01 16:03:03 -04:00
parent bc7dea7ad6
commit 158f4f3eaf
3 changed files with 104 additions and 53 deletions

26
ombi.py
View file

@ -9,15 +9,22 @@ import configuration
headers = {'Apikey': configuration.ombi_api_key} headers = {'Apikey': configuration.ombi_api_key}
def now_iso(): def now_iso():
now_iso = datetime.now(timezone.utc).astimezone().isoformat() now_iso = datetime.now(timezone.utc).astimezone().isoformat()
return now_iso return now_iso
def influx_sender(influx_payload): def influx_sender(influx_payload):
influx = InfluxDBClient(configuration.influxdb_url, configuration.influxdb_port, configuration.influxdb_username, influx = InfluxDBClient(configuration.influxdb_url,
configuration.influxdb_password, configuration.ombi_influxdb_db_name) configuration.influxdb_port,
configuration.influxdb_username,
configuration.influxdb_password,
configuration.ombi_influxdb_db_name)
influx.write_points(influx_payload) influx.write_points(influx_payload)
def get_total_requests(): def get_total_requests():
get_tv_requests = requests.get('{}/api/v1/Request/tv'.format( get_tv_requests = requests.get('{}/api/v1/Request/tv'.format(
configuration.ombi_url), headers=headers, configuration.ombi_url), headers=headers,
@ -50,6 +57,7 @@ def get_total_requests():
] ]
return influx_payload return influx_payload
def get_request_counts(): def get_request_counts():
get_request_counts = requests.get('{}/api/v1/Request/count'.format( get_request_counts = requests.get('{}/api/v1/Request/count'.format(
configuration.ombi_url), headers=headers, configuration.ombi_url), headers=headers,
@ -57,7 +65,7 @@ def get_request_counts():
influx_payload = [ influx_payload = [
{ {
"measurement": "Ombi", "measurement": "Ombi",
"tags": { "tags": {
"type": "Request_Counts" "type": "Request_Counts"
}, },
@ -71,15 +79,17 @@ def get_request_counts():
] ]
return influx_payload return influx_payload
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(prog='Ombi stats operations', parser = argparse.ArgumentParser(prog='Ombi stats operations',
description='Script to aid in data gathering from Ombi', formatter_class=RawTextHelpFormatter) description='Script to aid in data gathering from Ombi',
formatter_class=RawTextHelpFormatter)
parser.add_argument("--total", action='store_true', parser.add_argument("--total", action='store_true',
help='Get the total count of all requests') help='Get the total count of all requests')
parser.add_argument("--counts", action='store_true', parser.add_argument("--counts", action='store_true',
help='Get the count of pending, approved, and available requests') help='Get the count of pending, approved, and available requests')
opts = parser.parse_args() opts = parser.parse_args()

View file

@ -14,8 +14,12 @@ def now_iso():
def influx_sender(influx_payload): def influx_sender(influx_payload):
influx = InfluxDBClient(configuration.influxdb_url, configuration.influxdb_port, configuration.influxdb_username, influx = InfluxDBClient(configuration.influxdb_url,
configuration.influxdb_password, configuration.radarr_influxdb_db_name) configuration.influxdb_port,
configuration.influxdb_username,
configuration.influxdb_password,
configuration.radarr_influxdb_db_name)
influx.write_points(influx_payload) influx.write_points(influx_payload)
@ -36,7 +40,8 @@ def get_missing_movies():
for movie in movies.keys(): for movie in movies.keys():
if not movies[movie]['downloaded']: if not movies[movie]['downloaded']:
movie_name = ('{} ({})'.format(movies[movie]['title'], movies[movie]['year'])) movie_name = ('{} ({})'.format(movies[movie]['title'],
movies[movie]['year']))
missing.append((movie_name, movies[movie]['tmdbId'])) missing.append((movie_name, movies[movie]['tmdbId']))
for movie, id in missing: for movie, id in missing:
@ -78,10 +83,10 @@ def get_missing_avl():
for movie in movies.keys(): for movie in movies.keys():
if not movies[movie]['downloaded']: if not movies[movie]['downloaded']:
if movies[movie]['isAvailable'] is True: if movies[movie]['isAvailable'] is True:
movie_name = ('{} ({})'.format(movies[movie]['title'], movies[movie]['year'])) movie_name = ('{} ({})'.format(movies[movie]['title'],
movies[movie]['year']))
missing.append((movie_name, movies[movie]['tmdbId'])) missing.append((movie_name, movies[movie]['tmdbId']))
for movie, id in missing: for movie, id in missing:
influx_payload.append( influx_payload.append(
{ {
@ -118,8 +123,11 @@ def get_queue_movies():
queue_movies = {d['id']: d for d in get_movies} queue_movies = {d['id']: d for d in get_movies}
for movie in queue_movies.keys(): for movie in queue_movies.keys():
name = '{} ({})'.format(queue_movies[movie]['movie']['title'], queue_movies[movie]['movie']['year']) name = '{} ({})'.format(queue_movies[movie]['movie']['title'],
queue_movies[movie]['movie']['year'])
quality = (queue_movies[movie]['quality']['quality']['name']) quality = (queue_movies[movie]['quality']['quality']['name'])
protocol = (queue_movies[movie]['protocol'].upper()) protocol = (queue_movies[movie]['protocol'].upper())
if protocol == 'USENET': if protocol == 'USENET':
@ -155,16 +163,17 @@ def get_queue_movies():
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(prog='Radarr stats operations', parser = argparse.ArgumentParser(prog='Radarr stats operations',
description='Script to aid in data gathering from Radarr', formatter_class=RawTextHelpFormatter) description='Script to aid in data gathering from Radarr',
formatter_class=RawTextHelpFormatter)
parser.add_argument("--missing", action='store_true', parser.add_argument("--missing", action='store_true',
help='Get missing movies') help='Get missing movies')
parser.add_argument("--missing_avl", action='store_true', parser.add_argument("--missing_avl", action='store_true',
help='Get missing yet available movies') help='Get missing yet available movies')
parser.add_argument("--queue", action='store_true', parser.add_argument("--queue", action='store_true',
help='Get movies in queue') help='Get movies in queue')
opts = parser.parse_args() opts = parser.parse_args()

View file

@ -14,8 +14,12 @@ def now_iso():
def influx_sender(influx_payload): def influx_sender(influx_payload):
influx = InfluxDBClient(configuration.influxdb_url, configuration.influxdb_port, configuration.influxdb_username, influx = InfluxDBClient(configuration.influxdb_url,
configuration.influxdb_password, configuration.sonarr_influxdb_db_name) configuration.influxdb_port,
configuration.influxdb_username,
configuration.influxdb_password,
configuration.sonarr_influxdb_db_name)
influx.write_points(influx_payload) influx.write_points(influx_payload)
@ -37,11 +41,14 @@ def get_all_missing_shows():
tv_shows = {d['id']: d for d in get_tv_shows} tv_shows = {d['id']: d for d in get_tv_shows}
for show in tv_shows.keys(): for show in tv_shows.keys():
series_title = '{}'.format(tv_shows[show]['series']['title']) series_title = '{}'.format(tv_shows[show]['series']['title'])
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'],tv_shows[show]['episodeNumber'])
missing.append((series_title, sxe, tv_shows[show]['id'], tv_shows[show]['title'])) sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'],
tv_shows[show]['episodeNumber'])
missing.append((series_title, sxe, tv_shows[show]['id'],
tv_shows[show]['title']))
for series_title, sxe, id, episode_title in missing: for series_title, sxe, id, episode_title in missing:
influx_payload.append( influx_payload.append(
@ -92,8 +99,12 @@ def get_missing_shows(days_past):
for show in tv_shows.keys(): for show in tv_shows.keys():
if not (tv_shows[show]['hasFile']): if not (tv_shows[show]['hasFile']):
series_title = '{}'.format(tv_shows[show]['series']['title']) series_title = '{}'.format(tv_shows[show]['series']['title'])
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'], tv_shows[show]['episodeNumber'])
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'],
tv_shows[show]['episodeNumber'])
air_date = (tv_shows[show]['airDate']) air_date = (tv_shows[show]['airDate'])
missing.append((series_title, sxe, air_date, tv_shows[show]['id'])) missing.append((series_title, sxe, air_date, tv_shows[show]['id']))
for series_title, sxe, air_date, id in missing: for series_title, sxe, air_date, id in missing:
@ -140,27 +151,34 @@ def get_upcoming_shows():
for show in upcoming_shows.keys(): for show in upcoming_shows.keys():
series_title = '{}'.format(upcoming_shows[show]['series']['title']) series_title = '{}'.format(upcoming_shows[show]['series']['title'])
sxe = 'S{:0>2}E{:0>2}'.format(upcoming_shows[show]['seasonNumber'],upcoming_shows[show]['episodeNumber'])
upcoming.append((series_title, sxe, upcoming_shows[show]['id'], upcoming_shows[show]['title'], upcoming_shows[show]['airDate'])) sxe = 'S{:0>2}E{:0>2}'.format(upcoming_shows[show]['seasonNumber'],
upcoming_shows[show]['episodeNumber'])
upcoming.append((series_title, sxe,
upcoming_shows[show]['id'],
upcoming_shows[show]['title'],
upcoming_shows[show]['airDate']))
for series_title, sxe, id, episode_title, air_date in upcoming: for series_title, sxe, id, episode_title, air_date in upcoming:
influx_payload.append( influx_payload.append(
{ {
"measurement": "Sonarr", "measurement": "Sonarr",
"tags": { "tags": {
"type": "Soon", "type": "Soon",
"sonarrId": id, "sonarrId": id,
"server": server_id "server": server_id
}, },
"time": now, "time": now,
"fields": { "fields": {
"name": series_title, "name": series_title,
"epname": episode_title, "epname": episode_title,
"sxe": sxe, "sxe": sxe,
"airs": air_date "airs": air_date
} }
} }
) )
# Empty upcoming or else things get foo bared # Empty upcoming or else things get foo bared
upcoming = [] upcoming = []
@ -194,9 +212,16 @@ def get_future_shows(future_days):
for show in tv_shows.keys(): for show in tv_shows.keys():
series_title = '{}'.format(tv_shows[show]['series']['title']) series_title = '{}'.format(tv_shows[show]['series']['title'])
dl_status = int(tv_shows[show]['hasFile']) dl_status = int(tv_shows[show]['hasFile'])
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'], tv_shows[show]['episodeNumber'])
air_days.append((series_title, dl_status, sxe, tv_shows[show]['title'], tv_shows[show]['airDate'], tv_shows[show]['id'])) sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'],
tv_shows[show]['episodeNumber'])
air_days.append((series_title, dl_status, sxe,
tv_shows[show]['title'],
tv_shows[show]['airDate'],
tv_shows[show]['id']))
for series_title, dl_status, sxe, episode_title, air_date, id in air_days: for series_title, dl_status, sxe, episode_title, air_date, id in air_days:
influx_payload.append( influx_payload.append(
@ -245,15 +270,21 @@ def get_queue_shows():
for show in tv_shows.keys(): for show in tv_shows.keys():
series_title = '{}'.format(tv_shows[show]['series']['title']) series_title = '{}'.format(tv_shows[show]['series']['title'])
episode_title = '{}'.format(tv_shows[show]['episode']['title']) episode_title = '{}'.format(tv_shows[show]['episode']['title'])
protocol = (tv_shows[show]['protocol'].upper()) protocol = (tv_shows[show]['protocol'].upper())
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['episode']['seasonNumber'], tv_shows[show]['episode']['episodeNumber'])
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['episode']['seasonNumber'],
tv_shows[show]['episode']['episodeNumber'])
if protocol == 'USENET': if protocol == 'USENET':
protocol_id = 1 protocol_id = 1
else: else:
protocol_id = 0 protocol_id = 0
queue.append((series_title, episode_title, protocol, protocol_id, sxe, tv_shows[show]['id'])) queue.append((series_title, episode_title, protocol,
protocol_id, sxe, tv_shows[show]['id']))
for series_title, episode_title, protocol, protocol_id, sxe, id in queue: for series_title, episode_title, protocol, protocol_id, sxe, id in queue:
influx_payload.append( influx_payload.append(
@ -284,23 +315,24 @@ def get_queue_shows():
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(prog='Sonarr stats operations', parser = argparse.ArgumentParser(prog='Sonarr stats operations',
description='Script to aid in data gathering from Sonarr', formatter_class=RawTextHelpFormatter) description='Script to aid in data gathering from Sonarr',
formatter_class=RawTextHelpFormatter)
parser.add_argument("--missing", action='store_true', parser.add_argument("--missing", action='store_true',
help='Get all missing TV shows') help='Get all missing TV shows')
parser.add_argument("--missing_days", type=int, parser.add_argument("--missing_days", type=int,
help='Get missing TV shows in past X days') help='Get missing TV shows in past X days')
parser.add_argument("--upcoming", action='store_true', parser.add_argument("--upcoming", action='store_true',
help='Get upcoming TV shows') help='Get upcoming TV shows')
parser.add_argument("--future", type=int, parser.add_argument("--future", type=int,
help='Get TV shows on X days into the future. Includes today.' help='Get TV shows on X days into the future. Includes today.'
'\ni.e. --future 2 is Today and Tomorrow') '\ni.e. --future 2 is Today and Tomorrow')
parser.add_argument("--queue", action='store_true', parser.add_argument("--queue", action='store_true',
help='Get TV shows in queue') help='Get TV shows in queue')
opts = parser.parse_args() opts = parser.parse_args()