2018-02-12 16:31:38 -08:00
|
|
|
# Do not edit this script. Edit configuration.py
|
2018-02-09 22:40:32 -08:00
|
|
|
import requests
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from influxdb import InfluxDBClient
|
|
|
|
|
2018-02-12 16:31:38 -08:00
|
|
|
import configuration
|
2018-02-09 22:40:32 -08:00
|
|
|
|
|
|
|
current_time = datetime.now(timezone.utc).astimezone().isoformat()
|
2018-02-12 16:31:38 -08:00
|
|
|
headers = {'X-Api-Key': configuration.sonarr_api_key}
|
|
|
|
get_tv_shows = requests.get('{}/api/wanted/missing/?pageSize=1000'.format(configuration.sonarr_url),
|
2018-02-09 22:40:32 -08:00
|
|
|
headers=headers).json()['records']
|
|
|
|
tv_shows = {d['id']: d for d in get_tv_shows}
|
|
|
|
missing = []
|
|
|
|
influx_payload = []
|
|
|
|
|
|
|
|
for show in tv_shows.keys():
|
2018-04-17 12:28:02 -07:00
|
|
|
seriesTitle = '{}'.format(tv_shows[show]['series']['title'])
|
2018-04-17 12:33:02 -07:00
|
|
|
sxe = 'S{:0>2}E{:0>2}'.format(tv_shows[show]['seasonNumber'],tv_shows[show]['episodeNumber'])
|
2018-04-17 12:28:02 -07:00
|
|
|
missing.append((seriesTitle, sxe, tv_shows[show]['id'], tv_shows[show]['title']))
|
2018-02-09 22:40:32 -08:00
|
|
|
|
2018-04-17 12:28:02 -07:00
|
|
|
for seriesTitle, sxe, id, title in missing:
|
2018-02-09 22:40:32 -08:00
|
|
|
influx_payload.append(
|
|
|
|
{
|
2018-02-09 23:46:58 -08:00
|
|
|
"measurement": "Sonarr",
|
2018-02-09 22:40:32 -08:00
|
|
|
"tags": {
|
|
|
|
"type": "Missing",
|
|
|
|
"sonarrId": id
|
|
|
|
},
|
|
|
|
"time": current_time,
|
|
|
|
"fields": {
|
2018-04-17 12:28:02 -07:00
|
|
|
"name": seriesTitle,
|
|
|
|
"epname": title,
|
|
|
|
"sxe": sxe
|
2018-02-09 22:40:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2018-04-17 12:28:02 -07:00
|
|
|
|
|
|
|
get_upcoming_shows = requests.get('{}/api/calendar/'.format(configuration.sonarr_url),
|
|
|
|
headers=headers).json()
|
|
|
|
upcoming_shows = {d['id']: d for d in get_upcoming_shows}
|
|
|
|
upcoming = []
|
|
|
|
influx_payload2 = []
|
|
|
|
|
|
|
|
for show in upcoming_shows.keys():
|
|
|
|
seriesTitle = '{}'.format(upcoming_shows[show]['series']['title'])
|
2018-04-17 12:33:02 -07:00
|
|
|
sxe = 'S{:0>2}E{:0>2}'.format(upcoming_shows[show]['seasonNumber'],upcoming_shows[show]['episodeNumber'])
|
2018-04-17 12:28:02 -07:00
|
|
|
upcoming.append((seriesTitle, sxe, upcoming_shows[show]['id'], upcoming_shows[show]['title'], upcoming_shows[show]['airDate']))
|
|
|
|
|
|
|
|
for seriesTitle, sxe, id, title, airDate in upcoming:
|
|
|
|
influx_payload2.append(
|
|
|
|
{
|
|
|
|
"measurement": "Sonarr",
|
|
|
|
"tags": {
|
|
|
|
"type": "Soon",
|
|
|
|
"sonarrId": id
|
|
|
|
},
|
|
|
|
"time": current_time,
|
|
|
|
"fields": {
|
|
|
|
"name": seriesTitle,
|
|
|
|
"epname": title,
|
|
|
|
"sxe": sxe,
|
|
|
|
"airs": airDate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2018-02-09 22:40:32 -08:00
|
|
|
|
2018-02-12 16:31:38 -08:00
|
|
|
influx = InfluxDBClient(configuration.grafana_url, configuration.grafana_port, configuration.grafana_username,
|
|
|
|
configuration.grafana_password, configuration.sonarr_grafana_db_name)
|
2018-02-09 22:40:32 -08:00
|
|
|
influx.write_points(influx_payload)
|
2018-04-17 12:28:02 -07:00
|
|
|
influx.write_points(influx_payload2)
|