Thingiverseから3Dデータをダウンロードする

Pythonの変数展開が面倒すぎる。
Rubyに移りたくなる。
Curlのオプションはここを参考に。
http://www.hcn.zaq.ne.jp/___/unix/curl_manual.html

curl -o (保存するファイル名) (ダウンロード元URL) #こないだと方法が違う?

うまくいかない。wgetを使うことにする。
wgetはリダイレクトに対応してないらしい。 http://d.hatena.ne.jp/ksaito11/20090605/1244208059
ダウンロード先ディレクトリの指定は-Pオプションを使う。強制的にフォルダを作成できる。
http://blog.layer8.sh/ja/2012/03/31/wget_command/

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import urllib2
from BeautifulSoup import BeautifulSoup
from termcolor import colored

keyword = raw_input("キーワードを入力してください(例. chassis): ")
#keyword = "chassis"
baseurl = "http://www.thingiverse.com"
url = "http://www.thingiverse.com/search?q="+keyword+"&sa=Search"
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)

list = soup.findAll('tr')
result = []
for l in list:
    target_product =  l.p.a.string
    target_url =  l.p.a["href"]
    tupple = (str(target_product),str(target_url))
    result.append(tupple)
print result

for res in result:
    article = res[0]
    url = res[1]
    html = urllib2.urlopen(url).read()
    soup = BeautifulSoup(html)
    stl = re.compile('.stl$')
    ret = soup.findAll("div",{"class":"thing-status"})
    tupple = ()
    for r in ret:
        get = r.find("a",{"title":stl})
        if get:
            soup = BeautifulSoup(str(get))
            tupple = (soup.contents[0]["title"],soup.contents[0]["href"])
            title = tupple[0]
            title = str(title)
            href = tupple[1]
            url = baseurl + href
            url = str(url)
            #sentence = "curl -o "+title+" "+url #curlがうまくいかない。wgetで。
            #ちょっと調子に乗った
            print colored("Hooray, now you are downloading %(title)s !!"  % locals() ,'red',attrs=['reverse','blink'])
            sentence = "wget "+url+" -P " + keyword+"/"+article+"/"
            print sentence 
            os.system(" %(sentence)s " % locals())

どうでもいいけどコーヒー飲み過ぎで吐いた。