SWDesk
[Python] 최근 신규 키워드 찾아서 표시하기
inhae
2021. 8. 27. 22:58
예시 : 네이버 뉴스 수집 자료
* 최근 1개월간의 뉴스 제목에 포함된 단어들 중에서 최근 1주일 사이에만 등장하는 단어들 목록을 출력하는 프로그램
def LoadItems_NaverNews():
gs1 = cBGoogleSpread()
spreadName = "NaverNews"
date0 = datetime.now()
date1 = date0 - timedelta(weeks=1) # 1 week ago
date2 = date1 - relativedelta(months=1) # 1 month ago
try:
ss1 = gs1.OpenSpreadsheet(spreadName)
except Exception as e:
print("{???]", str(e))
return DataFrame()
sheetName = "Overview"
itemList_DF = gs1.ReadSheet(ss1, sheetName)
itemInfoList = itemList_DF.to_dict('records')
newNounsString = "Latest Nouns compared to a last month\n\n"
textKey = "Title"
dateKey = "I.Date"
for itemInfo1 in itemInfoList:
# print(itemInfo1)
keyWord1 = itemInfo1['Keyword']
itemData_DF=LoadData_NaverNews(itemInfo1)
newNouns = ExtractNewNounCount(itemData_DF, textKey, dateKey) # Dict
if not newNouns: continue
newNounsString += "["+keyWord1+"]\n"
for noun1 in newNouns.keys():
newNounsString += noun1 +", "
newNounsString += "\n\n"
#WordCloud01(titleString2)
print("[NewNounsString]", newNounsString)
print("[End] LoadItems_NaverShopping()")
return itemData_DF

반응형