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():
|
|
|
|
name = '{} - S{}E{}'.format(tv_shows[show]['series']['title'], tv_shows[show]['seasonNumber'],
|
|
|
|
tv_shows[show]['episodeNumber'])
|
|
|
|
missing.append((name, tv_shows[show]['id']))
|
|
|
|
|
|
|
|
for show, id in missing:
|
|
|
|
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": {
|
|
|
|
"name": show
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
|