From e5e153777e0dc22c783185b2e4e6527388244461 Mon Sep 17 00:00:00 2001 From: Envy_PC Date: Mon, 22 Apr 2024 12:03:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=91=EC=85=80=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20=EC=B9=B4=ED=94=BC=EB=A7=A8,?= =?UTF-8?q?=EC=86=8C=EC=8B=B1=EB=A7=A8=EC=9D=80=20=ED=95=B4=EB=8B=B9?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=EC=9D=84,=20=ED=82=A4=EC=9B=8C=EB=93=9C?= =?UTF-8?q?=EC=86=8C=EC=8B=B1=EC=9D=80=20=ED=8F=89=EA=B7=A0=EA=B0=80?= =?UTF-8?q?=EA=B2=A9=EC=9D=84=20=ED=94=8C=EB=A1=9C=EC=8A=A4=ED=94=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=85=EB=A0=A5.=20=EB=B0=B0=EC=86=A1=EB=B9=84?= =?UTF-8?q?=EB=8A=94=200=EC=9B=90=EC=B2=98=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baseDB.py | 1 + naverParser.py | 15 +++++++++++++-- taoseller.py | 11 ++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/baseDB.py b/baseDB.py index bd921a2..6c73ce0 100644 --- a/baseDB.py +++ b/baseDB.py @@ -82,6 +82,7 @@ def create_db(db_name): tao_imageUrl TEXT, tao_itemID INTEGER, tao_localimage TEXT, + merged_price INTEGER, unique_id TEXT, date_created TEXT DEFAULT (DATE('now', 'localtime')), time_created TEXT DEFAULT (TIME('now', 'localtime')), diff --git a/naverParser.py b/naverParser.py index 77992dd..503ebc1 100644 --- a/naverParser.py +++ b/naverParser.py @@ -151,8 +151,18 @@ def parse_naver_shopping(keyword_id, keyword, isBranch, branchCount, json_data, final_top_5_products = top5_products[:5] logger.debug(f"RANK 정렬상품 중 마지막으로 상위 제품 [{len(final_top_5_products)}]개 선택") + + merged_price = 0 + + for index, product in enumerate(final_top_5_products): + price = product.get("item", {}).get("price") + merged_price += price # 평균 가격 계산을 위해 + + merged_price = merged_price / len(final_top_5_products) + c = conn.cursor() + # original relatedTags 리스트 가져오기 related_tags_ori = next_data_json["props"]["pageProps"]["relatedTags"] @@ -245,8 +255,8 @@ def parse_naver_shopping(keyword_id, keyword, isBranch, branchCount, json_data, if count == 0: # 중복되는 데이터가 없으면 새로운 데이터 삽입 - c.execute("INSERT INTO NaverShopping (keyword_id, keyword, price, productTitle, category1Name, category2Name, category3Name, category4Name, cat_code, openDate, mallCount, keepCnt, overseaTp, reviewCount, reviewCountSum, scoreInfo, naverPayAdAccumulatedDisplayValue, mobileLowPrice, lowPrice, deliveryFeeContent, dlvryLowPrice, imageUrl, imgSz, searchKeyword, mallProductUrl, mallPcUrl, mallName, manuTag, purchaseCnt, relatedTags, rank, unique_id, date_created, time_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - (keyword_id+1, current_keyword, price, productTitle, category1Name, category2Name, category3Name, category4Name, cat_code, openDate, mallCount, keepCnt, overseaTp, reviewCount, reviewCountSum, scoreInfo, naverPayAdAccumulatedDisplayValue, mobileLowPrice, lowPrice, deliveryFeeContent, dlvryLowPrice, imageUrl, imgSz, searchKeyword, mallProductUrl, mallPcUrl, mallName, manuTag, purchaseCnt, current_keyword, rank, unique_id, date_created, time_created)) # keyword_id, item_name, price, purchase_count, related_keywords, rank는 적절하게 설정해야 합니다. + c.execute("INSERT INTO NaverShopping (keyword_id, keyword, price, productTitle, category1Name, category2Name, category3Name, category4Name, cat_code, openDate, mallCount, keepCnt, overseaTp, reviewCount, reviewCountSum, scoreInfo, naverPayAdAccumulatedDisplayValue, mobileLowPrice, lowPrice, deliveryFeeContent, dlvryLowPrice, imageUrl, imgSz, searchKeyword, mallProductUrl, mallPcUrl, mallName, manuTag, purchaseCnt, relatedTags, rank, merged_price, unique_id, date_created, time_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + (keyword_id+1, current_keyword, price, productTitle, category1Name, category2Name, category3Name, category4Name, cat_code, openDate, mallCount, keepCnt, overseaTp, reviewCount, reviewCountSum, scoreInfo, naverPayAdAccumulatedDisplayValue, mobileLowPrice, lowPrice, deliveryFeeContent, dlvryLowPrice, imageUrl, imgSz, searchKeyword, mallProductUrl, mallPcUrl, mallName, manuTag, purchaseCnt, current_keyword, rank, merged_price, unique_id, date_created, time_created)) # keyword_id, item_name, price, purchase_count, related_keywords, rank는 적절하게 설정해야 합니다. logger.debug(f"{current_keyword} DB업데이트 완료") else: # 중복되는 데이터가 있으면 업데이트 또는 무시 (여기서는 예시로 업데이트 로직을 추가함) @@ -259,4 +269,5 @@ def parse_naver_shopping(keyword_id, keyword, isBranch, branchCount, json_data, logger.debug(f"키워드 검색 결과 상품 [{keyword}]에 대한 [{len(final_top_5_products)}]개의 상품정보수집 완료") conn.commit() # Commit the transaction + #conn.close() # Close the connection diff --git a/taoseller.py b/taoseller.py index 0a3c9f0..d310807 100644 --- a/taoseller.py +++ b/taoseller.py @@ -1046,7 +1046,7 @@ class Ui_Dialog(QtWidgets.QDialog): # 데이터베이스에서 필요한 데이터 로드 conn = sqlite3.connect(db_name) - query = "SELECT MatchingUrl, keyword, MatchingCat, delvFee, packingFee, plusFee, manuTag FROM NaverShopping WHERE MatchingUrl IS NOT NULL" + query = "SELECT MatchingUrl, keyword, MatchingCat, delvFee, packingFee, plusFee, manuTag, merged_price FROM NaverShopping WHERE MatchingUrl IS NOT NULL" df = pd.read_sql_query(query, conn) conn.close() logger.debug("DB 읽기 완료") @@ -1077,14 +1077,15 @@ class Ui_Dialog(QtWidgets.QDialog): wb = xw.Book(file_name) ws = wb.sheets['multi_ss'] + final_delv = 0 + if 'sourcingman' in self.db_name or 'copyman' in self.db_name: - final_delv = 0 final_price = math.ceil((row['price'])*0.98 / 100) * 100 # 2%가격을 낮춘 후 100원단위 올림 else: - final_delv = row['delvFee'] + row['packingFee'] - final_price = row['plusFee'] - + # final_delv = row['delvFee'] + row['packingFee'] + # final_price = row['plusFee'] + final_price = row['murged_price'] # 데이터 삽입 for index, row in df_subset.iterrows():