Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d2e869bb | ||
|
|
ce9072124d | ||
|
|
f78ffcc595 |
@@ -0,0 +1,69 @@
|
||||
import requests
|
||||
import hashlib
|
||||
from apps.bitwarden.utils import bitwardenUtils
|
||||
|
||||
class betaserieUtils():
|
||||
url = "https://api.betaseries.com/members/auth"
|
||||
|
||||
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
|
||||
|
||||
__access_token = "0.7720f24b-4328-41ef-b70b-b419018270a3.nhBoRMSkfrlxqJVZ9W0W1g3lNFrmfI:35muVQz2mO3coR46bIZgcQ=="
|
||||
__organization_id = "a6361589-badd-4bde-9cb4-af8901161c0d"
|
||||
|
||||
bw = bitwardenUtils(__access_token,__organization_id)
|
||||
|
||||
__betaserie_token = bw.read_value_secret(token_UID)
|
||||
|
||||
payload = {}
|
||||
|
||||
headers = {
|
||||
'X-BetaSeries-Key': __betaserie_token,
|
||||
'X-BetaSeries-Token': __betaserie_token
|
||||
}
|
||||
|
||||
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 = 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']
|
||||
if verbose:
|
||||
print("Url request: "+str(url))
|
||||
print(response.text)
|
||||
|
||||
return episode_id
|
||||
|
||||
def mark_episodes_watched(self,episode_id,verbose=False):
|
||||
|
||||
url = "https://api.betaseries.com/episodes/watched?id=episode_id"
|
||||
|
||||
response = requests.request("POST", url, headers=self.headers, data=self.payload)
|
||||
if verbose:
|
||||
print("Url request: "+str(url))
|
||||
print(response.text)
|
||||
|
||||
print(response.text)
|
||||
@@ -24,23 +24,13 @@ class bitwardenUtils():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def __init__(self, access_token, organization_id):
|
||||
self.access_token = access_token
|
||||
self.organization_id = organization_id
|
||||
client = BitwardenClient(
|
||||
client_settings_from_dict(
|
||||
{
|
||||
"apiUrl": os.getenv("API_URL", "https://bitwarden.tryton.geeraert.eu/api"),
|
||||
"deviceType": DeviceType.SDK,
|
||||
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.tryton.geeraert.eu/identity"),
|
||||
"userAgent": "Python",
|
||||
}
|
||||
)
|
||||
)
|
||||
self.client.auth().login_access_token(self.access_token, self.state_path)
|
||||
def __init__(self, __access_token, __organization_id):
|
||||
self.__access_token = __access_token
|
||||
self.__organization_id = __organization_id
|
||||
self.client.auth().login_access_token(self.__access_token, self.state_path)
|
||||
|
||||
def create_project(self,project_name):
|
||||
project = self.client.projects().create(self.organization_id, project_name)
|
||||
project = self.client.projects().create(self.__organization_id, project_name)
|
||||
return project.data.id
|
||||
|
||||
def generate_strong_password(self):
|
||||
@@ -49,7 +39,7 @@ class bitwardenUtils():
|
||||
|
||||
def create_secret(self,project_id,secret_name,secret_value,description="description"):
|
||||
secret = self.client.secrets().create(
|
||||
self.organization_id,
|
||||
self.__organization_id,
|
||||
secret_name,
|
||||
secret_value,
|
||||
description,
|
||||
|
||||
Reference in New Issue
Block a user