Skip to content

Instantly share code, notes, and snippets.

@kurehajime
Created December 10, 2013 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurehajime/7890613 to your computer and use it in GitHub Desktop.
Save kurehajime/7890613 to your computer and use it in GitHub Desktop.
秒速でねこ画像を集めてネコヒルズ族を目指す ref: http://qiita.com/kurehajime/items/8a700db4f462521f4d77
$ sudo pip install httplib2
# -*- 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+")")
# -*- 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+")")
まずは元のプログラム。まぁこんな感じ。
complete!(5.79861092567)
改良版。ん?
complete!(5.06348490715)
改良版2回め。おお…
complete!(1.20627403259)
改良版3回め。うおおおお!
complete!(0.768098115921)
complete!(6.05635690689)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment