Skip to content

Instantly share code, notes, and snippets.

@say8425
Last active May 23, 2017 04:56
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 say8425/ffead9d396a3343bad50696e7b46c4e0 to your computer and use it in GitHub Desktop.
Save say8425/ffead9d396a3343bad50696e7b46c4e0 to your computer and use it in GitHub Desktop.
Get Korean Pharmacy with OpenAPI
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('\"', ''))
@say8425
Copy link
Author

say8425 commented Jan 20, 2017

Your generated secret key will be encoded UTF-8. So before use it, you must decode your secret key or server can not recognize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment