Skip to content

Instantly share code, notes, and snippets.

@non117
Created June 3, 2013 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save non117/5698055 to your computer and use it in GitHub Desktop.
Save non117/5698055 to your computer and use it in GitHub Desktop.
tumblrの全postをmongoDBに突っ込むアレ ※ クロール中にpostすると, バグります.
# -*- coding: utf-8 -*-
import requests
from pymongo import Connection
con = Connection("localhost", 27017)
db = con["tumblr"]
url = "http://api.tumblr.com/v2/blog/tumblr.non117.com/posts/"
params = {"api_key" : ""}
def fetch(offset):
params.update({"offset":offset})
json = requests.get(url, params=params).json()
posts = json["response"]["posts"]
if posts == []:
return -1
db.posts.insert(posts)
return len(posts)
if __name__ == "__main__":
offset = 0
while offset != -1:
offset += fetch(offset)
print offset
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment