Skip to content

Commit

Permalink
StashDbClient class
Browse files Browse the repository at this point in the history
  • Loading branch information
MinasukiHikimuna committed Aug 27, 2024
1 parent 8f87c31 commit 4b9e373
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pandas/libraries/StashDbClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import requests
import stashapi.log as logger


class StashDbClient(object):
def __init__(self, endpoint, api_key):
self.endpoint = endpoint
self.api_key = api_key

def query_scenes(self, scene_id):
query = """
query FindScene($scene_id: ID!) {
findScene(
id: $scene_id
) {
id
title
details
release_date
urls {
url
site {
name
url
}
}
studio {
id
name
parent {
id
name
}
}
images {
id
url
}
performers {
performer {
id
name
}
}
duration
code
tags {
id
name
}
}
}
"""
result = self._gql_query(
query, {"scene_id": scene_id}
)
return result

def _gql_query(self, query, variables=None):
headers = {"Content-Type": "application/json"}
if self.api_key:
headers["Apikey"] = self.api_key
response = requests.post(
self.endpoint,
json={"query": query, "variables": variables},
headers=headers,
)
if response.status_code == 200:
return response.json()
else:
logger.error(
f"Query failed with status code {response.status_code}: {response.text}"
)
return None

0 comments on commit 4b9e373

Please sign in to comment.