@@ -369,48 +369,42 @@ def extract_top_keywords(texts_with_weights, top_n=10):
369369 ]
370370
371371 try :
372- try :
373- texts_with_weights = fetch_texts_from_crawler (symbol , country )
374- if texts_with_weights :
375- # 점수 계산
376- keyword_score = calculate_keyword_score (texts_with_weights , weighted_keywords )
377- pattern_score = calculate_pattern_score (texts_with_weights , positive_patterns , negative_patterns )
378- sentiment_score = calculate_sentiment_score (texts_with_weights , weighted_keywords , positive_patterns , negative_patterns )
379-
380- final_score = (0.6 * keyword_score + 0.2 * sentiment_score + 0.2 * pattern_score )
381- final_score = max (0 , min (100 , int (round (final_score ))))
382-
383- # 키워드 추출
384- top_keywords = extract_top_keywords (texts_with_weights , top_n = 10 )
385-
386- result = {
387- "final_score" : final_score ,
388- "top_keywords" : top_keywords
389- }
390- else :
391- import random
392- random .seed (hash (symbol ) % 10000 )
393- final_score = random .randint (30 , 70 )
394- result = {
395- "final_score" : final_score ,
396- "top_keywords" : []
397- }
398- except Exception as crawler_error :
399- import random
400- random .seed (hash (symbol ) % 10000 )
401- final_score = random .randint (30 , 70 )
402- result = {
403- "final_score" : final_score ,
404- "top_keywords" : []
372+ texts_with_weights = fetch_texts_from_crawler (symbol , country )
373+ if not texts_with_weights :
374+ # 크롤링 데이터가 없으면 에러 반환 (점수 생성하지 않음)
375+ error_result = {
376+ "error" : "No data available from crawler" ,
377+ "symbol" : symbol ,
378+ "country" : country
405379 }
380+ print (json .dumps (error_result , ensure_ascii = False , indent = 2 ))
381+ sys .exit (1 )
382+
383+ # 점수 계산
384+ keyword_score = calculate_keyword_score (texts_with_weights , weighted_keywords )
385+ pattern_score = calculate_pattern_score (texts_with_weights , positive_patterns , negative_patterns )
386+ sentiment_score = calculate_sentiment_score (texts_with_weights , weighted_keywords , positive_patterns , negative_patterns )
387+
388+ final_score = (0.6 * keyword_score + 0.2 * sentiment_score + 0.2 * pattern_score )
389+ final_score = max (0 , min (100 , int (round (final_score ))))
390+
391+ # 키워드 추출
392+ top_keywords = extract_top_keywords (texts_with_weights , top_n = 10 )
393+
394+ result = {
395+ "final_score" : final_score ,
396+ "top_keywords" : top_keywords
397+ }
406398
407399 print (json .dumps (result , ensure_ascii = False , indent = 2 ))
408400 sys .exit (0 )
409401
410402 except Exception as e :
411- result = {
412- "final_score" : 50 ,
413- "top_keywords" : []
403+ # 크롤링 실패 시 에러 반환 (점수 생성하지 않음)
404+ error_result = {
405+ "error" : str (e ),
406+ "symbol" : symbol ,
407+ "country" : country
414408 }
415- print (json .dumps (result , ensure_ascii = False , indent = 2 ))
409+ print (json .dumps (error_result , ensure_ascii = False , indent = 2 ))
416410 sys .exit (1 )
0 commit comments