Files
Django_kube/django_code/apps/betaserie/utils.py
T
pi-ux-ce 04a216f643
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
adding the episode_seen option and fix potential mistake
2026-08-26 12:04:58 +01:00

127 lines
4.3 KiB
Python

import requests
import hashlib
from apps.bitwarden.utils import bitwardenUtils
import os
class betaserieUtils():
url = "https://api.betaseries.com/members/auth"
username_UID="7bc7ebd2-9c95-487f-9ba2-b47301591ef0"
password_UID="262c3246-203b-44e0-854b-b47301599730"
token_UID="2cf4be0f-f26f-473f-b8f1-b473016139e4"
#Adding __ to make the variable private and can't be access outside the class,
# only by the class itself ot the subclass
__bitwarden_access_token = os.environ.get('bitwarden_access_token')
__bitwarden_organization_id = os.environ.get('bitwarden_organization_id')
bw = bitwardenUtils(__bitwarden_access_token,__bitwarden_organization_id)
__betaserie_username = bw.read_value_secret(username_UID)
__betaserie_md5_password = bw.read_value_secret(password_UID)
__betaserie_apikey = bw.read_value_secret(token_UID)
payload = {
'login': __betaserie_username, # username or email
'password': __betaserie_md5_password # MD5 hashed password
}
headers = {
'X-BetaSeries-Key': __betaserie_apikey,
}
response = requests.post(url, headers=headers, data=payload)
#now set with the correct value
__betaserie_token = response.json()['token']
#set the __betaserie_token to the doct headers now
headers.update({'X-BetaSeries-Token': __betaserie_token})
def status_code(self):
print("Status code:", self.response.status_code)
print("Response:", self.response.json())
def identify_serie(self,serie_name,verbose=False):
#
# Usage
# show_id = beta.identify_serie("The simpsons")
# show_id = beta.identify_serie("The simpsons",verbose=True)
#
url = "https://api.betaseries.com/shows/search?title="+serie_name
response = requests.request("GET", url, headers=self.headers, data=self.payload)
if verbose:
print("Url request: "+str(url))
print(response.text)
show_id = response.json()['shows'][0]['id']
return show_id
def identify_episode(self,show_id,episode_number,verbose=False):
#
# Usage
# episode_id,episode_seen = beta.identify_episode(show_id,"S01E01",True)
#
url = "https://api.betaseries.com/episodes/search?show_id="+str(show_id)+"&number="+str(episode_number)
response = requests.request("GET", url, headers=self.headers, data=self.payload)
episode_id = response.json()['episode']['id']
episode_seen = response.json()['episode']['user']['seen']
if verbose:
print("Url request: "+str(url))
print(response.text)
return episode_id,episode_seen
def mark_episodes_watched(self,episode_id,verbose=False):
#
# Usage
# response = beta.mark_episodes_watched(episode_id,True)
#
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)+"&bulk=false"
response = requests.request("POST", url, headers=self.headers, data=self.payload)
if verbose:
print("Url request: "+str(url))
print(response.text)
return response.status_code
def unmark_episodes_watched(self,episode_id,verbose=False):
#
# Usage
# response = beta.unmark_episodes_watched(episode_id,True)
#
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)
response = requests.request("DELETE", url, headers=self.headers, data=self.payload)
if verbose:
print("Url request: "+str(url))
print(response.text)
return response.status_code
def series_information(self,show_id,verbose=False):
#
# Usage
#
url = "https://api.betaseries.com/shows/display?id="+str(show_id)
response = requests.request("GET", url, headers=self.headers, data=self.payload)
maximum_number_seasons = response.json()['show']['seasons']
if verbose : print("maximum_number_seasons: "+str(maximum_number_seasons))
seasons_details = response.json()['show']['seasons_details']
if verbose:
print("Url request: "+str(url))
print(response.text)
return seasons_details,maximum_number_seasons