Skip to content

Instantly share code, notes, and snippets.

@seka
Created April 18, 2015 12:43
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 seka/68e580bb1dc324986f6d to your computer and use it in GitHub Desktop.
Save seka/68e580bb1dc324986f6d to your computer and use it in GitHub Desktop.
Ameba Owndのある記事からデータを抜き出すために作ったスクリプト
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