Example #1
0
def get_new_detail(last_hid, total_count):
    print('get_new_detail')
    for hid in range(last_hid - total_count + 1, last_hid + 1):
        subject = helper.search('h_subject', ['hid'], [('hid', hid)], 1)
        if subject == []:
            print(hid)
            ykiho = helper.search('hospital', ['ykiho'], [('hid', hid)],
                                  1)[0]['ykiho']
            apicall.get_hos_detail(ykiho, hid)
            apicall.get_subject(ykiho, hid, False)
Example #2
0
def get_pharmacy_data(lat, lng, radius, page, row_num, isFirst):
    pharmacy = pharm_list(lat, lng, page, row_num, radius)

    for j in range(row_num):
        print(j)
        input = []
        # i 번째 page 에서 j 번째 병원의 data
        jth_pharm = pharmacy['response']['body']['items']['item'][j]
        # 병원 정보 api 에서 받아 올 수 있는 데이터를 먼저 받아온다.
        input.append(('lng', jth_pharm['XPos']))
        input.append(('lat', jth_pharm['YPos']))
        name = '\'' + jth_pharm['yadmNm'] + '\''
        input.append(('name', name))
        input.append(('addr', '\'' + jth_pharm['addr'] + '\''))
        input.append(('kind', 1))

        if isFirst is True:
            helper.insert('store', input)
        else:
            sto = helper.search('store', ['sid'], input[0:3], 1)
            print(sto)
            if sto != []:
                continue
            else:
                helper.insert('store', input)
Example #3
0
def get_subject(ykiho, hid, isFirst):
    if isFirst is False:
        check = helper.search('h_subject', ['hid'], [('hid', hid)], 1)
        if check != []:
            return

    # 병원 진료과목 받아오기 (병원의 데이터가 데이터 베이스에 먼저 저장이 되어 있어야 함)
    jth_hos_subject = hosp_subject(ykiho)
    while jth_hos_subject is None:
        jth_hos_subject = hosp_subject(ykiho)
    sub_total = jth_hos_subject['response']['body']['totalCount']
    jth_hos_subject = jth_hos_subject['response']['body']['items']

    if jth_hos_subject != '':
        #hid = helper.search('hospital', ['hid'], [('name',name)], 1)[0]['hid']
        if (sub_total != 1):
            for p in range(sub_total):
                subject_input = []
                subject_input.append(('hid', hid))
                subject = '\'' + jth_hos_subject['item'][p]['dgsbjtCdNm'] + '\''
                #print(subject)
                subject_input.append(('subject', subject))
                helper.insert('h_subject', subject_input)
        else:
            subject_input = []
            subject_input.append(('hid', hid))
            subject = '\'' + jth_hos_subject['item']['dgsbjtCdNm'] + '\''
            #print(subject)
            subject_input.append(('subject', subject))
            helper.insert('h_subject', subject_input)
Example #4
0
def get_hospital_data(lat, lng, radius, page, row_num, isFirst):

    print("page" + str(page))
    # page number 에 해당하는 page 를 읽어온다.
    hospital = hosp_list(lat, lng, page, row_num, radius)
    th = []
    for j in range(row_num):
        print(j)
        input = []
        # i 번째 page 에서 j 번째 병원의 data
        jth_hos = hospital['response']['body']['items']['item'][j]
        # 병원 정보 api 에서 받아 올 수 있는 데이터를 먼저 받아온다.
        input.append(('lng', jth_hos['XPos']))
        input.append(('lat', jth_hos['YPos']))
        name = '\'' + jth_hos['yadmNm'] + '\''
        input.append(('name', name))
        input.append(('dnum', jth_hos['drTotCnt']))
        input.append(('addr', '\'' + jth_hos['addr'] + '\''))
        input.append(('ykiho', '\'' + jth_hos['ykiho'] + '\''))

        # When getting data is not first, check the data exist.
        if isFirst is True:
            helper.insert('hospital', input)
        else:
            hos = helper.search('hospital', ['hid'], input, 1)
            if hos != []:
                continue
            else:
                helper.insert('hospital', input)
        '''
Example #5
0
def repair():
    radius = 1000
    lat = 37.5585146
    lng = 127.0331892
    i = 2288
    ykiho = helper.search('hospital', ['ykiho'], [('hid', i)], 1)[0]['ykiho']
    get_hos_detail(ykiho, i)
    get_subject(ykiho, i, True)
Example #6
0
def get_default():
    # 총 data 의 개수를 얻기 위해 하나의 데이터만 받아온다.
    radius = 5000
    lat = 37.5585146
    lng = 127.0331892

    total_count = get_hos_total(lat, lng, radius)
    print(total_count)
    # 한번에 100개씩 data 를 받아온다.
    pageNum = total_count // ONE_PAGE_NUM_COUNT
    remainder = total_count % ONE_PAGE_NUM_COUNT

    for i in range(1, pageNum + 2):
        if i == (pageNum + 1):
            k = remainder
        else:
            k = ONE_PAGE_NUM_COUNT
        get_hospital_data(lat, lng, radius, i, k, True)

    print('get_hospital done')

    # detail data 를 받아온다.
    for i in range(1, total_count + 1):
        print(i)
        ykiho = helper.search('hospital', ['ykiho'], [('hid', i)],
                              1)[0]['ykiho']
        get_hos_detail(ykiho, i)
        get_subject(ykiho, i, True)

    # 약국 데이터 받아오기
    total_pharm = get_pharm_total(lat, lng, radius)
    pageNum = total_pharm // ONE_PAGE_NUM_COUNT
    remainder = total_pharm % ONE_PAGE_NUM_COUNT
    for i in range(1, pageNum + 2):
        if i == (pageNum + 1):
            k = remainder
        else:
            k = ONE_PAGE_NUM_COUNT
        get_pharmacy_data(lat, lng, radius, i, k, True)