def mig_UPDATE_KMIG_KB_CMPX_TYP_MON_PRC(FUNC_ID): print("Function mig_UPDATE_KMIG_KB_CMPX_TYP_MON_PRC") dicFinalChg = chkFinalChg(FUNC_ID, 'KMIG_KB_CMPX_TYP_MON_PRC') if dicFinalChg == 0: REP_COM.log("UPDATE_KMIG_KB_PRC_STAT이 최근 갱신입니다") else: dicComplexTyp = REP_DAO.SELECT_RET_CMPX_TYP_CD2dic() for ComplexTyp in dicComplexTyp: MonthPriceList = [] url = URL.getURLKBRealEstatePastPriceInquery( 'S', '01', '', '', ComplexTyp['SMALL_KB_REGN_CD'], ComplexTyp['CMPX_IDF_ID'], ComplexTyp['HOUSE_TYP_SEQ'], dicFinalChg[0]['FINL_CHG_YYMM'], '210012', '', '') print(url) print(ComplexTyp) while 1: try: soup = getBeautifulShopFromKB(url) #print(soup) #time.sleep(1) for child in soup.find("tbody").find_all( "td", {"class", "t_r"}): MonthPriceList.append( child.text.replace(",", "").replace("-", "0")) seq = 0 conn = REP_DAO.repDBConnect() curs = conn.cursor( ) #Connection의 반복을 줄여 속도 향상을 위해 부득이하게 REP_MIG로 이관 시간당단지수 (468->1039개로 성능향상) for child in soup.find_all("th", scope="row"): dicMonthPrice = { 'CMPX_IDF_ID': ComplexTyp['CMPX_IDF_ID'], 'HOUSE_TYP_SEQ': ComplexTyp['HOUSE_TYP_SEQ'], 'STD_YYMM': child.text.replace(".", ""), 'UP_AVG_PRC': MonthPriceList[seq * 6 + 2], 'GNRL_AVG_PRC': MonthPriceList[seq * 6 + 1], 'DOWN_AVG_PRC': MonthPriceList[seq * 6 + 0], 'UP_JS_AVG_PRC': MonthPriceList[seq * 6 + 5], 'GNRL_JS_AVG_PRC': MonthPriceList[seq * 6 + 4], 'DOWN_JS_AVG_PRC': MonthPriceList[seq * 6 + 3] } seq = seq + 1 if dicFinalChg[0]['FINL_CHG_YYMM'] < dicMonthPrice[ 'STD_YYMM']: print("I") REP_DAO.INSERT_KMIG_KB_CMPX_TYP_MON_PRC( curs, dicMonthPrice) elif dicFinalChg[0]['FINL_CHG_YYMM'] == dicMonthPrice[ 'STD_YYMM']: print("U") REP_DAO.UPDATE_KMIG_KB_CMPX_TYP_MON_PRC( curs, dicMonthPrice) conn.commit() conn.close() break except Exception as e: #REP_COM.log("크롤링 도중 에러" + ComplexTyp['CMPX_IDF_ID'] + str(ComplexTyp['HOUSE_TYP_SEQ']) + str(e) ,"ERROR") continue print("여긴오나?") break
def migMontlyPrice(): print("Function migMontlyPrice") dicComplexTyp = REP_DAO.SELECT_RET_CMPX_TYP_CD2dic() for ComplexTyp in dicComplexTyp: MonthPriceList = [] url = URL.getURLKBRealEstatePastPriceInquery( 'S', '01', '', '', ComplexTyp['SMALL_KB_REGN_CD'], ComplexTyp['CMPX_IDF_ID'], ComplexTyp['HOUSE_TYP_SEQ'], '190001', '210012', '', '') print(url) soup = getBeautifulShopFromKB(url) for child in soup.find("tbody").find_all("td", {"class", "t_r"}): MonthPriceList.append( child.text.replace(",", "").replace("-", "0")) seq = 0 conn = REP_DAO.repDBConnect() curs = conn.cursor( ) #Connection의 반복을 줄여 속도 향상을 위해 부득이하게 REP_MIG로 이관 시간당단지수 (468->1039개로 성능향상) for child in soup.find_all("th", scope="row"): dicMonthPrice = { 'CMPX_IDF_ID': ComplexTyp['CMPX_IDF_ID'], 'HOUSE_TYP_SEQ': ComplexTyp['HOUSE_TYP_SEQ'], 'STD_YYMM': child.text.replace(".", ""), 'UP_AVG_PRC': MonthPriceList[seq * 6 + 2], 'GNRL_AVG_PRC': MonthPriceList[seq * 6 + 1], 'DOWN_AVG_PRC': MonthPriceList[seq * 6 + 0], 'UP_JS_AVG_PRC': MonthPriceList[seq * 6 + 5], 'GNRL_JS_AVG_PRC': MonthPriceList[seq * 6 + 4], 'DOWN_JS_AVG_PRC': MonthPriceList[seq * 6 + 3] } seq = seq + 1 REP_DAO.INSERT_KMIG_KB_CMPX_TYP_MON_PRC(curs, dicMonthPrice) conn.commit() conn.close()