Last active
May 23, 2017 04:56
-
-
Save say8425/ffead9d396a3343bad50696e7b46c4e0 to your computer and use it in GitHub Desktop.
Get Korean Pharmacy with OpenAPI
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
require 'json' | |
require 'rest-client' | |
url = 'http://openapi.e-gen.or.kr/openapi/service/rest/ErmctInsttInfoInqireService/getParmacyListInfoInqire'.freeze | |
key = 'Your Secret key' | |
params = {pageNo: 1, numOfRows: 100, ServiceKey: key} | |
data = RestClient.get(url, {params: params, accept: :json}) | |
total_count = (JSON.parse(data.body)['response']['body']['totalCount'] / 100.to_f).ceil | |
total_data = [] | |
total_count.times do |count| | |
params = {pageNo: count, numOfRows: 100, ServiceKey: key} | |
data = RestClient.get(url, {params: params, accept: :json}) | |
total_data.concat(JSON.parse(data.body)['response']['body']['items']['item']) | |
print "...#{count}/#{total_count}\r" | |
$stdout.flush | |
end | |
File.write('night-pharmacy.json', total_data.to_json.gsub('\"', '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your generated secret key will be encoded UTF-8. So before use it, you must decode your secret key or server can not recognize.