-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c959397
Showing
16 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API_URL=<your spooky URL>/api/v1/filament |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output_filaments | ||
.env |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API_URL=https://spoolman.disane.dev/api/v1/filament |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API_URL=<your spooky URL>/api/v1/filament |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output_filaments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output_filaments | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import requests | ||
import json | ||
import os | ||
from jsonschema import validate, ValidationError | ||
|
||
# URL to fetch the JSON Schema | ||
schema_url = "https://raw.githubusercontent.com/Donkie/SpoolmanDB/main/filaments.schema.json" | ||
|
||
# API URL to fetch filaments data | ||
api_url = "https://spoolman.disane.dev/api/v1/filament" | ||
|
||
# Fetch the schema from the provided URL | ||
response_schema = requests.get(schema_url) | ||
schema = response_schema.json() | ||
|
||
# Make the request to the API to fetch filaments data | ||
response_data = requests.get(api_url) | ||
data = response_data.json() | ||
|
||
# Function to merge colors safely | ||
def merge_colors(filament, new_color): | ||
if not any(color['name'] == new_color['name'] for color in filament["colors"]): | ||
filament["colors"].append(new_color) | ||
|
||
# Process data and organize by manufacturer | ||
manufacturers = {} | ||
for item in data: | ||
manufacturer_name = item["vendor"]["name"] | ||
|
||
# Initialize manufacturer entry if not present | ||
if manufacturer_name not in manufacturers: | ||
manufacturers[manufacturer_name] = { | ||
"manufacturer": manufacturer_name, | ||
"filaments": [] | ||
} | ||
|
||
# Search for existing material entry | ||
filament = next((f for f in manufacturers[manufacturer_name]["filaments"] if f["material"] == item["material"]), None) | ||
|
||
if filament: | ||
# If material entry exists, just add the new color | ||
merge_colors(filament, {"name": item["name"], "hex": item["color_hex"]}) | ||
else: | ||
# If no material entry exists, create new | ||
new_filament = { | ||
"name": f"{manufacturer_name} {{color_name}}", | ||
"material": item["material"], | ||
"density": item.get("density", 1.0), | ||
"weights": [{ | ||
"weight": item.get("weight", 0), | ||
"spool_weight": item.get("spool_weight", 0) | ||
}], | ||
"diameters": [item.get("diameter", 1.75)], | ||
"extruder_temp": item.get("settings_extruder_temp", 200), | ||
"bed_temp": item.get("settings_bed_temp", 60), | ||
"colors": [{"name": item["name"], "hex": item["color_hex"]}] | ||
} | ||
manufacturers[manufacturer_name]["filaments"].append(new_filament) | ||
|
||
# Validate data against the schema and save to JSON files if valid | ||
output_dir = 'output_filaments' | ||
os.makedirs(output_dir, exist_ok=True) | ||
for manufacturer, content in manufacturers.items(): | ||
try: | ||
validate(instance=content, schema=schema) | ||
output_filename = os.path.join(output_dir, f"{manufacturer.replace(' ', '_')}.json") | ||
with open(output_filename, 'w') as file: | ||
json.dump(content, file, indent=4) | ||
print(f"Data for {manufacturer} validated successfully and saved.") | ||
except ValidationError as ve: | ||
print(f"Validation error for {manufacturer}: {ve.message}") | ||
|
||
print(f"All data processed and valid data saved in directory: {output_dir}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import requests | ||
import json | ||
import os | ||
from jsonschema import validate, ValidationError | ||
|
||
# URL to fetch the JSON Schema | ||
filaments_schema_url = "https://raw.githubusercontent.com/Donkie/SpoolmanDB/main/filaments.schema.json" | ||
|
||
# API URL to fetch filaments data | ||
api_url = "https://spoolman.disane.dev/api/v1/filament" | ||
|
||
# Fetch the schema from the provided URL | ||
response_schema = requests.get(filaments_schema_url) | ||
schema = response_schema.json() | ||
|
||
# Make the request to the API to fetch filaments data | ||
response_data = requests.get(api_url) | ||
data = response_data.json() | ||
|
||
# Function to merge colors safely | ||
def merge_colors(filament, new_color): | ||
if not any(color['name'] == new_color['name'] for color in filament["colors"]): | ||
filament["colors"].append(new_color) | ||
|
||
# Process data and organize by manufacturer | ||
manufacturers = {} | ||
for item in data: | ||
manufacturer_name = item["vendor"]["name"] | ||
|
||
# Initialize manufacturer entry if not present | ||
if manufacturer_name not in manufacturers: | ||
manufacturers[manufacturer_name] = { | ||
"manufacturer": manufacturer_name, | ||
"filaments": [] | ||
} | ||
|
||
# Search for existing material entry | ||
filament = next((f for f in manufacturers[manufacturer_name]["filaments"] if f["material"] == item["material"]), None) | ||
|
||
if filament: | ||
# If material entry exists, just add the new color | ||
merge_colors(filament, {"name": item["name"], "hex": item["color_hex"]}) | ||
else: | ||
# If no material entry exists, create new | ||
new_filament = { | ||
"name": f"{manufacturer_name} {{color_name}}", | ||
"material": item["material"], | ||
"density": item.get("density", 1.0), | ||
"weights": [{ | ||
"weight": item.get("weight", 0), | ||
"spool_weight": item.get("spool_weight", 0) | ||
}], | ||
"diameters": [item.get("diameter", 1.75)], | ||
"extruder_temp": item.get("settings_extruder_temp", 200), | ||
"bed_temp": item.get("settings_bed_temp", 60), | ||
"colors": [{"name": item["name"], "hex": item["color_hex"]}] | ||
} | ||
manufacturers[manufacturer_name]["filaments"].append(new_filament) | ||
|
||
# Validate data against the schema and save to JSON files if valid | ||
output_dir = 'output_filaments' | ||
os.makedirs(output_dir, exist_ok=True) | ||
for manufacturer, content in manufacturers.items(): | ||
try: | ||
validate(instance=content, schema=schema) | ||
output_filename = os.path.join(output_dir, f"{manufacturer.replace(' ', '_')}.json") | ||
with open(output_filename, 'w') as file: | ||
json.dump(content, file, indent=4) | ||
print(f"Data for {manufacturer} validated successfully and saved.") | ||
except ValidationError as ve: | ||
print(f"Validation error for {manufacturer}: {ve.message}") | ||
|
||
print(f"All data processed and valid data saved in directory: {output_dir}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import requests | ||
import json | ||
import os | ||
from jsonschema import validate, ValidationError | ||
from dotenv import load_dotenv | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# URL to fetch the JSON Schema | ||
schema_url = "https://raw.githubusercontent.com/Donkie/SpoolmanDB/main/filaments.schema.json" | ||
|
||
# API URL to fetch filaments data (loaded from .env) | ||
api_url = os.getenv("API_URL") | ||
|
||
# Fetch the schema from the provided URL | ||
response_schema = requests.get(schema_url) | ||
schema = response_schema.json() | ||
|
||
# Make the request to the API to fetch filaments data | ||
response_data = requests.get(api_url) | ||
data = response_data.json() | ||
|
||
# Function to merge colors safely | ||
def merge_colors(filament, new_color): | ||
if not any(color['name'] == new_color['name'] for color in filament["colors"]): | ||
filament["colors"].append(new_color) | ||
|
||
# Process data and organize by manufacturer | ||
manufacturers = {} | ||
for item in data: | ||
manufacturer_name = item["vendor"]["name"] | ||
|
||
# Initialize manufacturer entry if not present | ||
if manufacturer_name not in manufacturers: | ||
manufacturers[manufacturer_name] = { | ||
"manufacturer": manufacturer_name, | ||
"filaments": [] | ||
} | ||
|
||
# Search for existing material entry | ||
filament = next((f for f in manufacturers[manufacturer_name]["filaments"] if f["material"] == item["material"]), None) | ||
|
||
if filament: | ||
# If material entry exists, just add the new color | ||
merge_colors(filament, {"name": item["name"], "hex": item["color_hex"]}) | ||
else: | ||
# If no material entry exists, create new | ||
new_filament = { | ||
"name": f"{manufacturer_name} {{color_name}}", | ||
"material": item["material"], | ||
"density": item.get("density", 1.0), | ||
"weights": [{ | ||
"weight": item.get("weight", 0), | ||
"spool_weight": item.get("spool_weight", 0) | ||
}], | ||
"diameters": [item.get("diameter", 1.75)], | ||
"extruder_temp": item.get("settings_extruder_temp", 200), | ||
"bed_temp": item.get("settings_bed_temp", 60), | ||
"colors": [{"name": item["name"], "hex": item["color_hex"]}] | ||
} | ||
manufacturers[manufacturer_name]["filaments"].append(new_filament) | ||
|
||
# Validate data against the schema and save to JSON files if valid | ||
output_dir = 'output_filaments' | ||
os.makedirs(output_dir, exist_ok=True) | ||
for manufacturer, content in manufacturers.items(): | ||
try: | ||
validate(instance=content, schema=schema) | ||
output_filename = os.path.join(output_dir, f"{manufacturer.replace(' ', '_')}.json") | ||
with open(output_filename, 'w') as file: | ||
json.dump(content, file, indent=4) | ||
print(f"Data for {manufacturer} validated successfully and saved.") | ||
except ValidationError as ve: | ||
print(f"Validation error for {manufacturer}: {ve.message}") | ||
|
||
print(f"All data processed and valid data saved in directory: {output_dir}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
attrs==23.2.0 | ||
beautifulsoup4==4.12.2 | ||
certifi==2023.7.22 | ||
charset-normalizer==3.3.0 | ||
distlib==0.3.8 | ||
filelock==3.13.1 | ||
idna==3.4 | ||
jsonschema==4.22.0 | ||
jsonschema-specifications==2023.12.1 | ||
network==0.1 | ||
platformdirs==4.2.0 | ||
referencing==0.35.1 | ||
requests==2.31.0 | ||
rpds-py==0.18.1 | ||
soupsieve==2.5 | ||
urllib3==2.0.6 | ||
virtualenv==20.25.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
attrs==23.2.0 | ||
beautifulsoup4==4.12.2 | ||
certifi==2023.7.22 | ||
charset-normalizer==3.3.0 | ||
distlib==0.3.8 | ||
filelock==3.13.1 | ||
idna==3.4 | ||
jsonschema==4.22.0 | ||
jsonschema-specifications==2023.12.1 | ||
network==0.1 | ||
platformdirs==4.2.0 | ||
referencing==0.35.1 | ||
requests==2.31.0 | ||
rpds-py==0.18.1 | ||
soupsieve==2.5 | ||
urllib3==2.0.6 | ||
virtualenv==20.25.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import requests | ||
import json | ||
import os | ||
from jsonschema import validate, ValidationError | ||
from dotenv import load_dotenv | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# URL to fetch the JSON Schema | ||
schema_url = "https://raw.githubusercontent.com/Donkie/SpoolmanDB/main/filaments.schema.json" | ||
|
||
# API URL to fetch filaments data (loaded from .env) | ||
api_url = os.getenv("API_URL") | ||
|
||
# Fetch the schema from the provided URL | ||
response_schema = requests.get(schema_url) | ||
schema = response_schema.json() | ||
|
||
# Make the request to the API to fetch filaments data | ||
response_data = requests.get(api_url) | ||
data = response_data.json() | ||
|
||
# Function to merge colors safely | ||
def merge_colors(filament, new_color): | ||
if not any(color['name'] == new_color['name'] for color in filament["colors"]): | ||
filament["colors"].append(new_color) | ||
|
||
# Process data and organize by manufacturer | ||
manufacturers = {} | ||
for item in data: | ||
manufacturer_name = item["vendor"]["name"] | ||
|
||
# Initialize manufacturer entry if not present | ||
if manufacturer_name not in manufacturers: | ||
manufacturers[manufacturer_name] = { | ||
"manufacturer": manufacturer_name, | ||
"filaments": [] | ||
} | ||
|
||
# Search for existing material entry | ||
filament = next((f for f in manufacturers[manufacturer_name]["filaments"] if f["material"] == item["material"]), None) | ||
|
||
if filament: | ||
# If material entry exists, just add the new color | ||
merge_colors(filament, {"name": item["name"], "hex": item["color_hex"]}) | ||
else: | ||
# If no material entry exists, create new | ||
new_filament = { | ||
"name": f"{manufacturer_name} {{color_name}}", | ||
"material": item["material"], | ||
"density": item.get("density", 1.0), | ||
"weights": [{ | ||
"weight": item.get("weight", 0), | ||
"spool_weight": item.get("spool_weight", 0) | ||
}], | ||
"diameters": [item.get("diameter", 1.75)], | ||
"extruder_temp": item.get("settings_extruder_temp", 200), | ||
"bed_temp": item.get("settings_bed_temp", 60), | ||
"colors": [{"name": item["name"], "hex": item["color_hex"]}] | ||
} | ||
manufacturers[manufacturer_name]["filaments"].append(new_filament) | ||
|
||
# Validate data against the schema and save to JSON files if valid | ||
output_dir = 'output_filaments' | ||
os.makedirs(output_dir, exist_ok=True) | ||
for manufacturer, content in manufacturers.items(): | ||
try: | ||
validate(instance=content, schema=schema) | ||
output_filename = os.path.join(output_dir, f"{manufacturer.replace(' ', '_')}.json") | ||
with open(output_filename, 'w') as file: | ||
json.dump(content, file, indent=4) | ||
print(f"Data for {manufacturer} validated successfully and saved.") | ||
except ValidationError as ve: | ||
print(f"Validation error for {manufacturer}: {ve.message}") | ||
|
||
print(f"All data processed and valid data saved in directory: {output_dir}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
attrs==23.2.0 | ||
beautifulsoup4==4.12.2 | ||
certifi==2023.7.22 | ||
charset-normalizer==3.3.0 | ||
distlib==0.3.8 | ||
filelock==3.13.1 | ||
idna==3.4 | ||
jsonschema==4.22.0 | ||
jsonschema-specifications==2023.12.1 | ||
network==0.1 | ||
platformdirs==4.2.0 | ||
referencing==0.35.1 | ||
requests==2.31.0 | ||
rpds-py==0.18.1 | ||
soupsieve==2.5 | ||
urllib3==2.0.6 | ||
virtualenv==20.25.1 |