Skip to content

Commit

Permalink
made time local to the function. Fixes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycajunrice committed Dec 11, 2018
1 parent 110aab2 commit b9b7d71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
9 changes: 4 additions & 5 deletions varken/ombi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class OmbiAPI(object):
def __init__(self, server, dbmanager):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
self.dbmanager = dbmanager
self.server = server
# Create session to reduce server web thread load, and globally define pageSize for all requests
Expand All @@ -20,7 +19,7 @@ def __repr__(self):
return "<ombi-{}>".format(self.server.id)

def get_total_requests(self):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
tv_endpoint = '/api/v1/Request/tv'
movie_endpoint = "/api/v1/Request/movie"

Expand All @@ -42,7 +41,7 @@ def get_total_requests(self):
"type": "Request_Total",
"server": self.server.id
},
"time": self.now,
"time": now,
"fields": {
"total": movie_requests + tv_requests,
"movies": movie_requests,
Expand All @@ -54,7 +53,7 @@ def get_total_requests(self):
self.dbmanager.write_points(influx_payload)

def get_request_counts(self):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
endpoint = '/api/v1/Request/count'

req = self.session.prepare_request(Request('GET', self.server.url + endpoint))
Expand All @@ -70,7 +69,7 @@ def get_request_counts(self):
"tags": {
"type": "Request_Counts"
},
"time": self.now,
"time": now,
"fields": {
"pending": requests.pending,
"approved": requests.approved,
Expand Down
11 changes: 4 additions & 7 deletions varken/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class RadarrAPI(object):
def __init__(self, server, dbmanager):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
self.dbmanager = dbmanager
self.server = server
# Create session to reduce server web thread load, and globally define pageSize for all requests
Expand All @@ -21,7 +20,7 @@ def __repr__(self):

def get_missing(self):
endpoint = '/api/movie'
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
influx_payload = []
missing = []

Expand All @@ -45,10 +44,8 @@ def get_missing(self):
ma = 1

movie_name = '{} ({})'.format(movie.title, movie.year)

missing.append((movie_name, ma, movie.tmdbId, movie.titleSlug))


for title, ma, mid, title_slug in missing:
hash_id = hashit('{}{}{}'.format(self.server.id, title, mid))
influx_payload.append(
Expand All @@ -62,7 +59,7 @@ def get_missing(self):
"name": title,
"titleSlug": title_slug
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id
}
Expand All @@ -73,7 +70,7 @@ def get_missing(self):

def get_queue(self):
endpoint = '/api/queue'
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
influx_payload = []
queue = []

Expand Down Expand Up @@ -124,7 +121,7 @@ def get_queue(self):
"protocol_id": protocol_id,
"titleSlug": title_slug
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id
}
Expand Down
21 changes: 10 additions & 11 deletions varken/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class SonarrAPI(object):
def __init__(self, server, dbmanager):
# Set Time of initialization
self.now = datetime.now(timezone.utc).astimezone().isoformat()
self.dbmanager = dbmanager
self.today = str(date.today())
self.server = server
# Create session to reduce server web thread load, and globally define pageSize for all requests
self.session = Session()
Expand All @@ -24,9 +21,10 @@ def __repr__(self):

def get_missing(self):
endpoint = '/api/calendar'
today = str(date.today())
last_days = str(date.today() + timedelta(days=-self.server.missing_days))
self.now = datetime.now(timezone.utc).astimezone().isoformat()
params = {'start': last_days, 'end': self.today}
now = datetime.now(timezone.utc).astimezone().isoformat()
params = {'start': last_days, 'end': today}
influx_payload = []
missing = []

Expand Down Expand Up @@ -63,7 +61,7 @@ def get_missing(self):
"sxe": sxe,
"airs": air_date
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id

Expand All @@ -75,11 +73,12 @@ def get_missing(self):

def get_future(self):
endpoint = '/api/calendar/'
self.now = datetime.now(timezone.utc).astimezone().isoformat()
today = str(date.today())
now = datetime.now(timezone.utc).astimezone().isoformat()
future = str(date.today() + timedelta(days=self.server.future_days))
influx_payload = []
air_days = []
params = {'start': self.today, 'end': future}
params = {'start': today, 'end': future}

req = self.session.prepare_request(Request('GET', self.server.url + endpoint, params=params))
get = connection_handler(self.session, req, self.server.verify_ssl)
Expand Down Expand Up @@ -116,7 +115,7 @@ def get_future(self):
"airs": air_date,
"downloaded": dl_status
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id
}
Expand All @@ -128,7 +127,7 @@ def get_future(self):
def get_queue(self):
influx_payload = []
endpoint = '/api/queue'
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
queue = []

req = self.session.prepare_request(Request('GET', self.server.url + endpoint))
Expand Down Expand Up @@ -168,7 +167,7 @@ def get_queue(self):
"protocol": protocol,
"protocol_id": protocol_id
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id
}
Expand Down
8 changes: 3 additions & 5 deletions varken/tautulli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

class TautulliAPI(object):
def __init__(self, server, dbmanager, data_folder):
# Set Time of initialization
self.now = datetime.now(timezone.utc).astimezone().isoformat()
self.dbmanager = dbmanager
self.server = server
self.session = Session()
Expand All @@ -23,7 +21,7 @@ def __repr__(self):
return "<tautulli-{}>".format(self.server.id)

def get_activity(self):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
now = datetime.now(timezone.utc).astimezone().isoformat()
influx_payload = []

req = self.session.prepare_request(Request('GET', self.server.url + self.endpoint))
Expand Down Expand Up @@ -119,7 +117,7 @@ def get_activity(self):
"device_type": session.platform,
"server": self.server.id
},
"time": self.now,
"time": now,
"fields": {
"hash": hash_id
}
Expand All @@ -133,7 +131,7 @@ def get_activity(self):
"type": "current_stream_stats",
"server": self.server.id
},
"time": self.now,
"time": now,
"fields": {
"stream_count": int(get['stream_count']),
"total_bandwidth": int(get['total_bandwidth']),
Expand Down

0 comments on commit b9b7d71

Please sign in to comment.