Advertisement
Guest User

dl

a guest
Nov 13th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Shapeways.com login info:
  4. username=$1
  5. password=$2
  6.  
  7. # stuff we need
  8. zip_download_dir=./ZIP_files
  9. stl_extract_dir=./STL_files
  10.  
  11. extract_item_from_zip () {
  12.     mkdir -p ${stl_extract_dir}
  13.     unzip -o $1 -d ${stl_extract_dir}
  14. }
  15.  
  16. download_item () {
  17.     mkdir -p ${zip_download_dir}
  18.     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
  19.  
  20.     extract_item_from_zip ${zip_download_dir}/$1.zip
  21. }  
  22.  
  23. get_items_to_download_from_page () {
  24.     # Crawl sub-page for products
  25.     item_IDs=(`wget -q $1 -O - | \
  26.         grep -i -o 'href="https://www.shapeways.com/product/.*=user-profile"' | \
  27.         sed -n 's|.*href="https://www.shapeways.com/product/\([A-Za-z0-9]\+\).*|\1|p' | \
  28.         uniq`)
  29.  
  30.     for item in "${item_IDs[@]}"; do
  31.         download_item ${item}
  32.     done
  33. }
  34.  
  35. # Start
  36. # Login to shapeways.com
  37. #echo "Logging in to shapeways..."
  38. #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}"
  39.  
  40. # Determine all the product sub-pages
  41. # Begin by getting a list of the page navigation links. Only the first few and the last will be shown
  42. user_page="https://www.shapeways.com/designer/mz4250/creations?s=0#more-products"
  43. user_page_links=(`wget -q ${user_page} -O - | \
  44.     grep -i 'href="/designer/mz4250/creations?s=[0-9]\+#more-products"' | \
  45.     sed -n 's/.*href="\([^"]*\).*/\1/p'`)
  46.  
  47. models_per_page=`echo ${user_page_links[1]} | sed -n 's/.*?s=\([0-9]\+\).*/\1/p'`
  48. # This is second-to-last instead of last because of the "next" button, which should be ignored
  49. models_at_last_page=`echo ${user_page_links[-2]} | sed -n 's/.*?s=\([0-9]\+\).*/\1/p'`
  50. num_pages=`expr $models_at_last_page  / $models_per_page + 1`
  51.  
  52. for ((i=0 ; i < $num_pages ; i++)); do
  53.     num=`expr $i \* $models_per_page`
  54.     page="https://www.shapeways.com/designer/mz4250/creations?s=${num}#more-products"
  55.     get_items_to_download_from_page ${page}
  56. done
  57.  
  58. # Finish
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement