Last active
December 22, 2015 02:39
-
-
Save wagurano/6405005 to your computer and use it in GitHub Desktop.
전국 어린이집 세부 정보를 BAAS.IO 에 입력하는 루비 코드
This file contains 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
코드 | 이름 | 주소 | 보험가입 | 시설유형 | 시설인증 | 시설특성 | 어린이집명 | 영역별 점수 | 운영형태 | 인가일 | 인증결과발표 | 인증유효기간 | 전화번호 | 종합 결과 | 지역 | 통학차량 | 정원 | 아동현원 | 종사자현원 | 총점 | 위도 | 경도 | 0세아 반 | 1세아 반 | 2세아 반 | 3세아 반 | 4.5세이상 반 | 4세아 반 | 5세아 반 | 누리장애아반 | 방과후반 | 새벽반 | 시간연장반 | 일시보육반(0.2세) | 장애아방과후반 | 장애아종일반 | 혼합반(0.1세) | 혼합반(1.2세) | 혼합반(2.3세) | 혼합반(3.4세 이상) | 휴일반 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
code | name | address | insurances | category | certification | features | nursery_name | certification_area | size | granted_date | certification_date | certificatication_begin-thru | phone | result_point | region | bus | children_quota | children | staff | total_point | latitude | longitude | child0 | child1 | child2 | child3 | child4p | child4 | child5 | child_h | child_after | child_early | child_ext | child_tmp | child_h_after | child_h_all | child0_1 | child1_2 | child2_3 | child3_4 | child_off | |
11110000009 | 이화어린이집 | 서울특별시 종로구 율곡로20길 3 | 상해 (가입(안전공제회)):화재 (가입):배상 (가입(안전공제회)) | 민간 | 인증시설(평가인증) | 시간연장형:휴일보육 | 2004-05-03 | 02-747-2686 | 운영(신고) | 64 | 60 | 17 | 37.57494521 | 127.0051251 | 7 | 14 | 18 | 9 | 12 | 0 | 0 | 0 | 0 | 0 | 31 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 22 | |||||||||
11110000011 | 삼청어린이집 | 서울특별시 종로구 삼청로7길 26 | 상해 (가입(안전공제회)):화재 (가입):배상 (가입(안전공제회)) | 국공립 | 인증시설(평가인증) | 시간연장형 | 1999-09-01 | 02-723-0155 | 미운영 | 32 | 31 | 8 | 37.58400574 | 126.9804875 | 0 | 9 | 6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | 0 | 0 | 0 | 0 | 0 | 0 | 16 | 0 |
This file contains 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
#encoding: utf-8 | |
require "net/https" | |
require 'net/http' | |
require 'uri' | |
require 'csv' | |
require 'json' | |
class Object | |
def numeric? | |
!(self.to_s =~ /^-?\d+(\.\d*)?$/).nil? | |
end | |
end | |
TIMEOUT_CNT = 42 | |
def put_baas post_data | |
path = '/2e*******************/e8**********/nurseries' | |
headers = { | |
'Authorization' => 'Bearer ****************************************', # your baas code | |
'Content-Type' => 'application/json' | |
} | |
begin | |
retries = TIMEOUT_CNT | |
begin | |
Timeout::timeout(5) { | |
uri = URI.parse("https://api.baas.io") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
resp, post_data = http.post(path, post_data, headers) | |
puts resp.body | |
} | |
rescue Timeout::Error | |
retries -= 1 | |
if retries > 0 | |
puts "sleep" | |
sleep 0.42 | |
retry | |
else | |
puts "raise" | |
raise | |
end | |
end | |
end | |
end # end of def | |
data = "" | |
header = "" | |
File.open('nursery_info.csv') do |file| | |
file.readline | |
header = file.readline.chomp.split(',') | |
until file.eof? | |
line = file.readline.chomp.split(',') | |
idx = 0 | |
record = "{" | |
line.each do |field| | |
list = field.split(':') | |
if list.length == 0 | |
#do nothing | |
else | |
record << "\"#{header[idx]}\":" | |
if list.length > 1 | |
record << "[" | |
pp = "" | |
list.each {|ll| pp << "\"#{ll}\","} | |
record << "#{pp[0,pp.length-1]}" | |
record << "]" | |
else | |
if field.numeric? | |
record << "#{field}" | |
else | |
record << "\"#{field}\"" | |
end | |
end | |
if idx == line.length - 1 | |
record << "}" | |
put_baas record | |
else | |
record << ", " | |
end | |
end | |
idx += 1 | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment