Created
December 10, 2013 13:32
-
-
Save kurehajime/7890613 to your computer and use it in GitHub Desktop.
秒速でねこ画像を集めてネコヒルズ族を目指す ref: http://qiita.com/kurehajime/items/8a700db4f462521f4d77
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
$ sudo pip install httplib2 |
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
# -*- coding: utf-8 -*- | |
import feedparser | |
import urllib | |
import os | |
import time | |
def download_picture(q, count=10): | |
u"""qの画像をcount件 取ってくる。""" | |
count = str(count) | |
feed = feedparser.parse("https://picasaweb.google.com/data/feed/base/all?q=" + q + "&max-results=" + count) | |
pic_urls = [] | |
for entry in feed['entries']: | |
url = entry.content[0].src | |
if not os.path.exists(os.path.join(os.path.dirname(__file__), q)): | |
os.mkdir(os.path.join(os.path.dirname(__file__), q)) | |
urllib.urlretrieve(url, os.path.join(os.path.dirname(__file__), q, os.path.basename(url))) | |
print('download:' + url) | |
if __name__ == "__main__": | |
time1=time.time() | |
download_picture("cat", 10) | |
time1_2=str(time.time()-time1) | |
print("complete!("+time1_2+")") |
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
# -*- coding: utf-8 -*- | |
import feedparser | |
import httplib2 | |
import os | |
import time | |
def download_picture(q, count=10): | |
u"""qの画像をcount件 取ってくる。""" | |
count = str(count) | |
feed = feedparser.parse("https://picasaweb.google.com/data/feed/base/all?q=" + q + "&max-results=" + count) | |
pic_urls = [] | |
http = httplib2.Http(".chache") | |
for entry in feed['entries']: | |
url = entry.content[0].src | |
open(os.path.join(os.path.join(os.path.dirname(__file__), q),os.path.basename(url)),'wb').write(http.request(url)[1]) | |
print('download:' + url) | |
if __name__ == "__main__": | |
time1=time.time() | |
download_picture("cat", 10) | |
time1_2=str(time.time()-time1) | |
print("complete!("+time1_2+")") |
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
まずは元のプログラム。まぁこんな感じ。 | |
complete!(5.79861092567) | |
改良版。ん? | |
complete!(5.06348490715) | |
改良版2回め。おお… | |
complete!(1.20627403259) | |
改良版3回め。うおおおお! | |
complete!(0.768098115921) |
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
complete!(6.05635690689) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment