Skip to content

Commit

Permalink
added the ability to pull per request chart. Fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycajunrice committed Dec 16, 2018
1 parent 4392a2f commit 056d211
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Varken.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def threaded(job):
if server.request_type_counts:
schedule.every(server.request_type_run_seconds).seconds.do(threaded, OMBI.get_request_counts)
if server.request_total_counts:
schedule.every(server.request_total_run_seconds).seconds.do(threaded, OMBI.get_total_requests)
schedule.every(server.request_total_run_seconds).seconds.do(threaded, OMBI.get_all_requests)

if CONFIG.ciscoasa_enabled:
for firewall in CONFIG.ciscoasa_firewalls:
Expand Down
89 changes: 81 additions & 8 deletions varken/ombi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from requests import Session, Request
from datetime import datetime, timezone

from varken.helpers import connection_handler
from varken.structures import OmbiRequestCounts
from varken.helpers import connection_handler, hashit
from varken.structures import OmbiRequestCounts, OmbiMovieRequest, OmbiTVRequest


class OmbiAPI(object):
Expand All @@ -18,7 +18,7 @@ def __init__(self, server, dbmanager):
def __repr__(self):
return "<ombi-{}>".format(self.server.id)

def get_total_requests(self):
def get_all_requests(self):
now = datetime.now(timezone.utc).astimezone().isoformat()
tv_endpoint = '/api/v1/Request/tv'
movie_endpoint = "/api/v1/Request/movie"
Expand All @@ -31,8 +31,20 @@ def get_total_requests(self):
if not all([get_tv, get_movie]):
return

movie_requests = len(get_movie)
tv_requests = len(get_tv)
movie_request_count = len(get_movie)
tv_request_count = len(get_tv)

try:
tv_show_requests = [OmbiTVRequest(**show) for show in get_tv]
except TypeError as e:
self.logger.error('TypeError has occurred : %s while creating OmbiTVRequest structure', e)
return

try:
movie_requests = [OmbiMovieRequest(**movie) for movie in get_movie]
except TypeError as e:
self.logger.error('TypeError has occurred : %s while creating OmbiMovieRequest structure', e)
return

influx_payload = [
{
Expand All @@ -43,12 +55,73 @@ def get_total_requests(self):
},
"time": now,
"fields": {
"total": movie_requests + tv_requests,
"movies": movie_requests,
"tv_shows": tv_requests
"total": movie_request_count + tv_request_count,
"movies": movie_request_count,
"tv_shows": tv_request_count
}
}
]
# Request Type: Movie = 1, TV Show = 0
for movie in movie_requests:
hash_id = hashit(f'{movie.id}{movie.theMovieDbId}{movie.title}')
status = None
# Denied = 0, Approved = 1, Completed = 2
if movie.denied:
status = 0
elif movie.approved and movie.available:
status = 2
elif movie.approved:
status = 1

influx_payload.append(
{
"measurement": "Ombi",
"tags": {
"type": "Requests",
"server": self.server.id,
"request_type": 1,
"status": status,
"title": movie.title,
"requested_user": movie.requestedUser['userAlias'],
"requested_date": movie.requestedDate
},
"time": now,
"fields": {
"hash": hash_id
}
}
)

for show in tv_show_requests:
hash_id = hashit(f'{show.id}{show.tvDbId}{show.title}')
status = None
# Denied = 0, Approved = 1, Completed = 2
if show.childRequests[0]['denied']:
status = 0
elif show.childRequests[0]['approved'] and show.childRequests[0]['available']:
status = 2
elif show.childRequests[0]['approved']:
status = 1

influx_payload.append(
{
"measurement": "Ombi",
"tags": {
"type": "Requests",
"server": self.server.id,
"request_type": 0,
"status": status,
"title": show.title,
"requested_user": show.childRequests[0]['requestedUser']['userAlias'],
"requested_date": show.childRequests[0]['requestedDate']
},
"time": now,
"fields": {
"hash": hash_id
}
}
)


self.dbmanager.write_points(influx_payload)

Expand Down
47 changes: 47 additions & 0 deletions varken/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,50 @@ class Movie(NamedTuple):
physicalReleaseNote: str = None
website: str = None
id: int = None

class OmbiMovieRequest(NamedTuple):
theMovieDbId: int = None
issueId: None = None
issues: None = None
subscribed: bool = None
showSubscribe: bool = None
rootPathOverride: int = None
qualityOverride: int = None
imdbId: str = None
overview: str = None
posterPath: str = None
releaseDate: str = None
digitalReleaseDate: None = None
status: str = None
background: str = None
released: bool = None
digitalRelease: bool = None
title: str = None
approved: bool = None
markedAsApproved: str = None
requestedDate: str = None
available: bool = None
markedAsAvailable: None = None
requestedUserId: str = None
denied: bool = None
markedAsDenied: str = None
deniedReason: None = None
requestType: int = None
requestedUser: dict = None
canApprove: bool = None
id: int = None

class OmbiTVRequest(NamedTuple):
tvDbId: int = None
imdbId: str = None
qualityOverride: None = None
rootFolder: None = None
overview: str = None
title: str = None
posterPath: str = None
background: str = None
releaseDate: str = None
status: str = None
totalSeasons: int = None
childRequests: list = None
id: int = None

0 comments on commit 056d211

Please sign in to comment.