At-Home Additive ManufacturingPermalink
Curiosity was sparked by a Kickstarter campaign by AnkerMake in the fall of 2022.
This is my printer: the M5 AnkerMake
Lessons in progress:
- Best initial 3D prints to motiviate and delight
- Most important slicer settings to understand
- Editing STL models with 3d modeling software (starting with TinkerCad)
Demo of gistPermalink
import requests | |
def download_remote_to_local(url: str, save_folder: str = '.') -> str: | |
""" | |
Downloads a file from a given URL and saves it to the specified folder. | |
If no URL is provided, it downloads a default open-access article about dogs. | |
The function handles PDF content types, adds a custom User-Agent header, | |
and uses chunked transfer to efficiently handle large files. It returns | |
a success message with the file path or an error message if the download fails. | |
Args: | |
url (str): The URL of the file to download. If None, uses a default URL. | |
save_folder (str): The folder to save the downloaded file. Defaults to current directory. | |
Returns: | |
str: A message indicating success or failure of the download, including the file path or error details. | |
""" | |
# URL of an open-access article about dogs | |
if url is None: | |
url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2251326/pdf/jeab-89-02-247.pdf" | |
# Specify the intended path and filename | |
SAVE_PATH = f"{save_folder}/{url.split('/')[-1]}" | |
# Add headers to the request | |
headers = { | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" | |
} | |
error_msg = '' | |
# Stream the download with headers and Raise an exception for HTTP errors | |
try: | |
response = requests.get(url, headers=headers, stream=True) | |
response.raise_for_status() | |
if response.headers.get('Content-Type').startswith('application/pdf') & (not(SAVE_PATH.endswith('.pdf'))): | |
SAVE_PATH = f"{SAVE_PATH}.pdf" | |
with open(SAVE_PATH, "wb") as file: | |
for chunk in response.iter_content(chunk_size=8192): | |
file.write(chunk) | |
except requests.exceptions.HTTPError as http_err: | |
error_msg = f"HTTP error occurred: {http_err}" | |
except Exception as err: | |
error_msg = f"An error occurred: {err}" | |
if os.path.exists(SAVE_PATH): | |
return f"File: {SAVE_PATH} downloaded successfully!" | |
else: | |
return f"File: {SAVE_PATH} was not found\n\nThis was the error {error_msg}" | |
More to come soon:Permalink
- Network graph based on schema.org showing objects to print
- List of awesome resources for learning slicing settings