Skip to content

Instantly share code, notes, and snippets.

@progd
Created April 29, 2012 00:56
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 progd/2522991 to your computer and use it in GitHub Desktop.
Save progd/2522991 to your computer and use it in GitHub Desktop.
Fetch LDRFullFeed JSON and fix type
# -*- coding: utf-8 -*-
require 'open-uri'
require 'json'
LDR_FULL_FEED_URL = 'http://wedata.net/databases/LDRFullFeed/items_all.json'
OUTFILE = 'ldrfullfeed.json'
REPLACE = {
'^http://matome\.naver\.jp/odai/[0-9]+/[0-9]+' => 'SUB',
'^http://matome\.naver\.jp/' => 'GEN',
}
puts "Fetching siteinfo from #{LDR_FULL_FEED_URL}"
siteinfo = JSON::parse(open(LDR_FULL_FEED_URL).read)
REPLACE.each { |target_url, type|
candidate = siteinfo.select { |info| info['data']['url'] == target_url }
raise "検索結果が 1 件でない" unless candidate.size == 1
puts "Replacing: #{target_url}: #{candidate[0]['data']['type']} to #{type}"
candidate[0]['data']['type'] = type
}
open(OUTFILE, 'w') { |f| f.write JSON::dump(siteinfo) }
puts "Wrote to #{OUTFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment