Clean up request totals. Upstream change sct/overseerr#2426
This commit is contained in:
		
							parent
							
								
									5e8c8eb5ce
								
							
						
					
					
						commit
						08c49698a7
					
				
					 5 changed files with 12 additions and 73 deletions
				
			
		|  | @ -160,9 +160,6 @@ if __name__ == "__main__": | ||||||
|     if CONFIG.overseerr_enabled: |     if CONFIG.overseerr_enabled: | ||||||
|         for server in CONFIG.overseerr_servers: |         for server in CONFIG.overseerr_servers: | ||||||
|             OVERSEER = OverseerrAPI(server, DBMANAGER) |             OVERSEER = OverseerrAPI(server, DBMANAGER) | ||||||
|             if server.get_request_total_counts: |  | ||||||
|                 at_time = schedule.every(server.request_total_run_seconds).seconds |  | ||||||
|                 at_time.do(thread, OVERSEER.get_total_requests).tag("overseerr-{}-get_total_requests".format(server.id)) |  | ||||||
|             if server.get_request_status_counts: |             if server.get_request_status_counts: | ||||||
|                 at_time = schedule.every(server.request_status_run_seconds).seconds |                 at_time = schedule.every(server.request_status_run_seconds).seconds | ||||||
|                 at_time.do(thread, OVERSEER.get_request_status_counts).tag("overseerr-{}-get_request_status_counts" |                 at_time.do(thread, OVERSEER.get_request_status_counts).tag("overseerr-{}-get_request_status_counts" | ||||||
|  |  | ||||||
|  | @ -101,8 +101,6 @@ url = overseerr.domain.tld | ||||||
| apikey = xxxxxxxxxxxxxxxx | apikey = xxxxxxxxxxxxxxxx | ||||||
| ssl = false | ssl = false | ||||||
| verify_ssl = false | verify_ssl = false | ||||||
| get_request_total_counts = true |  | ||||||
| request_total_run_seconds = 300 |  | ||||||
| get_request_status_counts = true | get_request_status_counts = true | ||||||
| request_status_run_seconds = 300 | request_status_run_seconds = 300 | ||||||
| get_latest_requests = true | get_latest_requests = true | ||||||
|  |  | ||||||
|  | @ -297,12 +297,6 @@ class INIParser(object): | ||||||
|                             get_latest_requests = boolcheck(env.get( |                             get_latest_requests = boolcheck(env.get( | ||||||
|                                 f'VRKN_{envsection}_GET_LATEST_REQUESTS', |                                 f'VRKN_{envsection}_GET_LATEST_REQUESTS', | ||||||
|                                 self.config.get(section, 'get_latest_requests'))) |                                 self.config.get(section, 'get_latest_requests'))) | ||||||
|                             num_latest_requests_to_fetch = int(env.get( |  | ||||||
|                                 f'VRKN_{envsection}_NUM_LATEST_REQUESTS', |  | ||||||
|                                 self.config.getint(section, 'num_latest_requests_to_fetch'))) |  | ||||||
|                             num_latest_requests_seconds = int(env.get( |  | ||||||
|                                 f'VRKN_{envsection}_NUM_LATEST_REQUESTS_SECONDS', |  | ||||||
|                                 self.config.getint(section, 'num_latest_requests_seconds'))) |  | ||||||
|                             get_request_total_counts = boolcheck(env.get( |                             get_request_total_counts = boolcheck(env.get( | ||||||
|                                 f'VRKN_{envsection}_GET_REQUEST_TOTAL_COUNTS', |                                 f'VRKN_{envsection}_GET_REQUEST_TOTAL_COUNTS', | ||||||
|                                 self.config.get(section, 'get_request_total_counts'))) |                                 self.config.get(section, 'get_request_total_counts'))) | ||||||
|  | @ -318,8 +312,6 @@ class INIParser(object): | ||||||
| 
 | 
 | ||||||
|                             server = OverseerrServer(id=server_id, url=scheme + url, api_key=apikey, |                             server = OverseerrServer(id=server_id, url=scheme + url, api_key=apikey, | ||||||
|                                                      verify_ssl=verify_ssl, get_latest_requests=get_latest_requests, |                                                      verify_ssl=verify_ssl, get_latest_requests=get_latest_requests, | ||||||
|                                                      num_latest_requests_to_fetch=num_latest_requests_to_fetch, |  | ||||||
|                                                      num_latest_requests_seconds=num_latest_requests_seconds, |  | ||||||
|                                                      get_request_total_counts=get_request_total_counts, |                                                      get_request_total_counts=get_request_total_counts, | ||||||
|                                                      request_total_run_seconds=request_total_run_seconds, |                                                      request_total_run_seconds=request_total_run_seconds, | ||||||
|                                                      get_request_status_counts=get_request_status_counts, |                                                      get_request_status_counts=get_request_status_counts, | ||||||
|  |  | ||||||
|  | @ -18,63 +18,6 @@ class OverseerrAPI(object): | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return f"<overseerr-{self.server.id}>" |         return f"<overseerr-{self.server.id}>" | ||||||
| 
 | 
 | ||||||
|     def get_total_requests(self): |  | ||||||
|         now = datetime.now(timezone.utc).astimezone().isoformat() |  | ||||||
|         endpoint = '/api/v1/request?take=200&filter=all&sort=added' |  | ||||||
| 
 |  | ||||||
|         req = self.session.prepare_request(Request('GET', self.server.url + endpoint)) |  | ||||||
|         get_req = connection_handler(self.session, req, self.server.verify_ssl) or [] |  | ||||||
| 
 |  | ||||||
|         if not any([get_req]): |  | ||||||
|             self.logger.error('No json replies. Discarding job') |  | ||||||
|             return |  | ||||||
| 
 |  | ||||||
|         tv_requests = [] |  | ||||||
|         movie_requests = [] |  | ||||||
| 
 |  | ||||||
|         for result in get_req['results']: |  | ||||||
|             if result['type'] == 'tv': |  | ||||||
|                 try: |  | ||||||
|                     tv_requests.append(OverseerrRequest(**result)) |  | ||||||
|                 except TypeError as e: |  | ||||||
|                     self.logger.error('TypeError has occurred : %s while creating OverseerrRequest structure for show. ' |  | ||||||
|                                       'data attempted is: %s', e, result) |  | ||||||
| 
 |  | ||||||
|             if result['type'] == 'movie': |  | ||||||
|                 try: |  | ||||||
|                     movie_requests.append(OverseerrRequest(**result)) |  | ||||||
|                 except TypeError as e: |  | ||||||
|                     self.logger.error('TypeError has occurred : %s while creating OverseerrRequest \ |  | ||||||
|                                       structure for movie. ' |  | ||||||
|                                       'data attempted is: %s', e, result) |  | ||||||
| 
 |  | ||||||
|         if tv_requests: |  | ||||||
|             tv_request_count = len(tv_requests) |  | ||||||
| 
 |  | ||||||
|         if movie_requests: |  | ||||||
|             movie_request_count = len(movie_requests) |  | ||||||
| 
 |  | ||||||
|         influx_payload = [ |  | ||||||
|             { |  | ||||||
|                 "measurement": "Overseerr", |  | ||||||
|                 "tags": { |  | ||||||
|                     "type": "Request_Totals", |  | ||||||
|                     "server": self.server.id |  | ||||||
|                 }, |  | ||||||
|                 "time": now, |  | ||||||
|                 "fields": { |  | ||||||
|                     "total": movie_request_count + tv_request_count, |  | ||||||
|                     "movies": movie_request_count, |  | ||||||
|                     "tv": tv_request_count |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         ] |  | ||||||
| 
 |  | ||||||
|         if influx_payload: |  | ||||||
|             self.dbmanager.write_points(influx_payload) |  | ||||||
|         else: |  | ||||||
|             self.logger.debug("Empty dataset for overseerr module. Discarding...") |  | ||||||
| 
 |  | ||||||
|     def get_request_status_counts(self): |     def get_request_status_counts(self): | ||||||
|         now = datetime.now(timezone.utc).astimezone().isoformat() |         now = datetime.now(timezone.utc).astimezone().isoformat() | ||||||
|         endpoint = '/api/v1/request/count' |         endpoint = '/api/v1/request/count' | ||||||
|  | @ -97,7 +40,12 @@ class OverseerrAPI(object): | ||||||
|                     "pending": requests.pending, |                     "pending": requests.pending, | ||||||
|                     "approved": requests.approved, |                     "approved": requests.approved, | ||||||
|                     "processing": requests.processing, |                     "processing": requests.processing, | ||||||
|                     "available": requests.available |                     "available": requests.available, | ||||||
|  |                     "total": requests.total, | ||||||
|  |                     "movies": requests.movie, | ||||||
|  |                     "tv": requests.tv, | ||||||
|  |                     "declined": requests.declined | ||||||
|  | 
 | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         ] |         ] | ||||||
|  | @ -139,8 +87,8 @@ class OverseerrAPI(object): | ||||||
|                             "request_type": 0, |                             "request_type": 0, | ||||||
|                             "status": get_tv_req['mediaInfo']['status'], |                             "status": get_tv_req['mediaInfo']['status'], | ||||||
|                             "title": get_tv_req['name'], |                             "title": get_tv_req['name'], | ||||||
|                             "requested_user": get_tv_req['mediaInfo']['requests'][0]['requestedBy']['plexUsername'], |                             "requested_date": get_tv_req['mediaInfo']['requests'][0]['media']['createdAt'] | ||||||
|                             "requested_date": get_tv_req['mediaInfo']['requests'][0]['requestedBy']['createdAt'] |                             "requested_date": get_movie_req['mediaInfo']['requests'][0]['media']['createdAt'] | ||||||
|                         }, |                         }, | ||||||
|                         "time": now, |                         "time": now, | ||||||
|                         "fields": { |                         "fields": { | ||||||
|  |  | ||||||
|  | @ -212,6 +212,10 @@ class OverseerrRequestCounts(NamedTuple): | ||||||
|     approved: int = None |     approved: int = None | ||||||
|     processing: int = None |     processing: int = None | ||||||
|     available: int = None |     available: int = None | ||||||
|  |     total: int = None | ||||||
|  |     movie: int = None | ||||||
|  |     tv: int = None | ||||||
|  |     declined: int = None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # Sonarr | # Sonarr | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue