import all
This commit is contained in:
commit
881baaa1ed
25 files changed
+1779
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
import dotenv
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
USERNAME = os.getenv("BRICKSET_USERNAME")
|
||||
PASS = os.getenv("BRICKSET_PASS")
|
||||
BRICKSET_API_KEY = os.getenv("BRICKSET_API_KEY")
|
||||
|
||||
debug = False # Set to True to enable debug output
|
||||
|
||||
|
||||
def login(username, password):
|
||||
url = "https://brickset.com/api/v3.asmx/login"
|
||||
headers = {"UserAgent": "Edderkop/0.1"}
|
||||
params = {
|
||||
"UserAgent": "Edderkop/0.1",
|
||||
"username": username,
|
||||
"password": password,
|
||||
"apiKey": BRICKSET_API_KEY,
|
||||
}
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
if debug:
|
||||
print(f"[@DEBUG] Login response: {response.status_code} - {response.text}\n")
|
||||
return response.json()
|
||||
|
||||
|
||||
def get_set(set_number: int) -> dict:
|
||||
login_response = login(USERNAME, PASS)
|
||||
url = f"https://brickset.com/api/v3.asmx/getSets?apiKey={BRICKSET_API_KEY}&userHash={login_response["hash"]}¶ms={{'setNumber' : '{set_number}-1'}}"
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
our_set = {
|
||||
"set_num": data["sets"][0]["number"],
|
||||
"set_name": data["sets"][0]["name"],
|
||||
"set_theme": data["sets"][0]["theme"],
|
||||
"set_image": data["sets"][0]["image"]["thumbnailURL"],
|
||||
"set_barcode": data["sets"][0]["barcode"]["UPC"],
|
||||
"set_retailprice": round(data["sets"][0]["LEGOCom"]["US"]["retailPrice"]),
|
||||
}
|
||||
# add PW 10% b4 tax
|
||||
our_set.update(
|
||||
{"set_adjustredprice": our_set + ((10 / 100) * our_set["set_retailprice"])}
|
||||
)
|
||||
our_set["pw_name"] = (
|
||||
f"{our_set['set_num']} - {our_set["set_theme"].upper()} {our_set['set_name']}"
|
||||
)
|
||||
if our_set["set_retailprice"] >= 110:
|
||||
our_set["requires_manual_price"] = True
|
||||
return our_set
|
||||
|
||||
elif response.status_code == 500:
|
||||
raise Exception(
|
||||
"Internal Server Error: Please check the API key and parameters."
|
||||
)
|
||||
else:
|
||||
raise Exception("Unexpected response from the API.")
|
||||
Reference in new issue
Block a user