From 4f1ec17538001f1057dd5b8382dd0eda5e4d898f Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Sun, 2 Dec 2018 21:59:46 -0600 Subject: [PATCH] testing hashit --- Varken/helpers.py | 11 +++++++++++ Varken/sonarr.py | 34 ++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Varken/helpers.py b/Varken/helpers.py index e464b89..b441e3b 100644 --- a/Varken/helpers.py +++ b/Varken/helpers.py @@ -1,6 +1,7 @@ import os import time import tarfile +import hashlib import geoip2.database from typing import NamedTuple from os.path import abspath, join @@ -65,6 +66,7 @@ class Movie(NamedTuple): website: str = None id: int = None + class Queue(NamedTuple): movie: dict = None series: dict = None @@ -95,6 +97,7 @@ class SonarrServer(NamedTuple): queue: bool = False queue_run_seconds: int = 30 + class RadarrServer(NamedTuple): id: int = None url: str = None @@ -343,6 +346,7 @@ def geoip_download(): tar.extract(files, abspath(join('.', 'data'))) os.remove(tar_dbfile) + def geo_lookup(ipaddress): dbfile = abspath(join('.', 'data', 'GeoLite2-City.mmdb')) @@ -360,3 +364,10 @@ def geo_lookup(ipaddress): reader = geoip2.database.Reader(dbfile) return reader.city(ipaddress) + + +def hashit(string): + encoded = string.encode() + hashed = hashlib.md5(encoded).hexdigest() + + return hashed diff --git a/Varken/sonarr.py b/Varken/sonarr.py index ae09c2e..6409af5 100644 --- a/Varken/sonarr.py +++ b/Varken/sonarr.py @@ -2,7 +2,7 @@ from requests import Session from datetime import datetime, timezone, date, timedelta from Varken.logger import logging -from Varken.helpers import TVShow, Queue +from Varken.helpers import TVShow, Queue, hashit class SonarrAPI(object): @@ -38,20 +38,23 @@ class SonarrAPI(object): missing.append((show.series['title'], sxe, show.airDate, show.title, show.id)) for series_title, sxe, air_date, episode_title, sonarr_id in missing: + hash_id = hashit('{}{}{}'.format(self.server.id, series_title, sxe)) influx_payload.append( { "measurement": "Sonarr", "tags": { "type": "Missing", "sonarrId": sonarr_id, - "server": self.server.id - }, - "time": self.now, - "fields": { + "server": self.server.id, "name": series_title, "epname": episode_title, "sxe": sxe, "airs": air_date + }, + "time": self.now, + "fields": { + "hash": hash_id + } } ) @@ -77,21 +80,23 @@ class SonarrAPI(object): air_days.append((show.series['title'], show.hasFile, sxe, show.title, show.airDate, show.id)) for series_title, dl_status, sxe, episode_title, air_date, sonarr_id in air_days: + hash_id = hashit('{}{}{}'.format(self.server.id, series_title, sxe)) influx_payload.append( { "measurement": "Sonarr", "tags": { "type": "Future", "sonarrId": sonarr_id, - "server": self.server.id - }, - "time": self.now, - "fields": { + "server": self.server.id, "name": series_title, "epname": episode_title, "sxe": sxe, "airs": air_date, "downloaded": dl_status + }, + "time": self.now, + "fields": { + "hash": hash_id } } ) @@ -120,22 +125,23 @@ class SonarrAPI(object): protocol_id, sxe, show.id)) for series_title, episode_title, protocol, protocol_id, sxe, sonarr_id in queue: + hash_id = hashit('{}{}{}'.format(self.server.id, series_title, sxe)) influx_payload.append( { "measurement": "Sonarr", "tags": { "type": "Queue", "sonarrId": sonarr_id, - "server": self.server.id - - }, - "time": self.now, - "fields": { + "server": self.server.id, "name": series_title, "epname": episode_title, "sxe": sxe, "protocol": protocol, "protocol_id": protocol_id + }, + "time": self.now, + "fields": { + "hash": hash_id } } )