Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Shapeways.com login info:
- username=$1
- password=$2
- # stuff we need
- zip_download_dir=./ZIP_files
- stl_extract_dir=./STL_files
- extract_item_from_zip () {
- mkdir -p ${stl_extract_dir}
- unzip -o $1 -d ${stl_extract_dir}
- }
- download_item () {
- mkdir -p ${zip_download_dir}
- wget --referer="https://www.shapeways.com/login/json-shapeways" --cookies=on --keep-session-cookies --load-cookies=cookies.txt -O ${zip_download_dir}/$1.zip https://www.shapeways.com/product/download/$1
- extract_item_from_zip ${zip_download_dir}/$1.zip
- }
- get_items_to_download_from_page () {
- # Crawl sub-page for products
- item_IDs=(`wget -q $1 -O - | \
- grep -i -o 'href="https://www.shapeways.com/product/.*=user-profile"' | \
- sed -n 's|.*href="https://www.shapeways.com/product/\([A-Za-z0-9]\+\).*|\1|p' | \
- uniq`)
- for item in "${item_IDs[@]}"; do
- download_item ${item}
- done
- }
- # Start
- # Login to shapeways.com
- #echo "Logging in to shapeways..."
- #wget https://www.shapeways.com/login/json-shapeways --quiet --delete-after --cookies=on --keep-session-cookies --save-cookies cookies.txt --post-data "username=${username}&password=${password}"
- # Determine all the product sub-pages
- # Begin by getting a list of the page navigation links. Only the first few and the last will be shown
- user_page="https://www.shapeways.com/designer/mz4250/creations?s=0#more-products"
- user_page_links=(`wget -q ${user_page} -O - | \
- grep -i 'href="/designer/mz4250/creations?s=[0-9]\+#more-products"' | \
- sed -n 's/.*href="\([^"]*\).*/\1/p'`)
- models_per_page=`echo ${user_page_links[1]} | sed -n 's/.*?s=\([0-9]\+\).*/\1/p'`
- # This is second-to-last instead of last because of the "next" button, which should be ignored
- models_at_last_page=`echo ${user_page_links[-2]} | sed -n 's/.*?s=\([0-9]\+\).*/\1/p'`
- num_pages=`expr $models_at_last_page / $models_per_page + 1`
- for ((i=0 ; i < $num_pages ; i++)); do
- num=`expr $i \* $models_per_page`
- page="https://www.shapeways.com/designer/mz4250/creations?s=${num}#more-products"
- get_items_to_download_from_page ${page}
- done
- # Finish
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement