Created
April 18, 2015 12:43
-
-
Save seka/68e580bb1dc324986f6d to your computer and use it in GitHub Desktop.
Ameba Owndのある記事からデータを抜き出すために作ったスクリプト
This file contains hidden or 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
https = require 'https' | |
async = require 'async' | |
global = { | |
url: 'https://api.amebaowndme.com/v2/public/blogPosts?limit=200&page=&siteId=11014&sortType=recent' | |
} | |
requestURL = (callback) => | |
req = https.get global.url, (res) -> | |
@res = "" | |
res.setEncoding 'utf8' | |
res.on 'data', (chunk) => | |
@res += chunk | |
res.on 'end', () => | |
json = JSON.parse(@res) | |
callback null, json | |
req.on 'error', (err) -> | |
throw 'request error' | |
callback err, 1 | |
parseObj = (json, callback) => | |
for j in json.body | |
console.log "title: #{j.title}" | |
# フォーマットがあってない人がいる? | |
# 三項演算子の方が綺麗に見えるかもしれない | |
if j.contents[0]?.value | |
console.log "name: #{j.contents[0].value}" | |
if j.contents[0]?.url | |
console.log "image: #{j.contents[0].url}" | |
base64Encode j.contents[0].url, (err, image) -> console.log image | |
if j.contents[1]?.value | |
console.log "name: #{j.contents[1].value}" | |
if j.contents[1]?.url | |
console.log "image: #{j.contents[1].url}" | |
base64Encode j.contents[1].url, (err, image) -> console.log image | |
do main = () -> | |
# 3. 画像をどういう形式で保存するのか決める(base64かurlを保持するか | |
# 4. databaseに追加する処理を書く | |
async.waterfall [ | |
requestURL | |
parseObj | |
], (err, result) -> | |
console.log err if err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment