Kims12 commited on
Commit
c98c67f
ยท
verified ยท
1 Parent(s): 49065f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -115,25 +115,29 @@ def get_search_volumes(keyword):
115
  try:
116
  data = api.get_keywords_data([keyword])
117
  if 'keywordList' in data and len(data['keywordList']) > 0:
118
- item = data['keywordList'][0]
119
- monthly_pc = item.get('monthlyPcQcCnt', 0)
120
- monthly_mobile = item.get('monthlyMobileQcCnt', 0)
121
-
122
- if isinstance(monthly_pc, str):
123
- monthly_pc = monthly_pc.replace(',', '').replace('< 10', '0')
124
- try:
125
- monthly_pc = int(monthly_pc)
126
- except ValueError:
127
- monthly_pc = 0
128
- if isinstance(monthly_mobile, str):
129
- monthly_mobile = monthly_mobile.replace(',', '').replace('< 10', '0')
130
- try:
131
- monthly_mobile = int(monthly_mobile)
132
- except ValueError:
133
- monthly_mobile = 0
134
-
135
- total_searches = monthly_pc + monthly_mobile
136
- return (keyword, monthly_pc, monthly_mobile, total_searches)
 
 
 
 
137
  else:
138
  return (keyword, 0, 0, 0)
139
  except Exception as e:
@@ -219,10 +223,10 @@ def get_monthly_search_volumes(keywords, include_related_keywords=True):
219
  for future in blog_futures:
220
  try:
221
  keyword, blog_count = future.result()
222
- temp_results.append((keyword, 0, 0, 0, blog_count))
223
  except Exception as e:
224
  print(f"Error fetching blog count for keyword '{keyword}': {e}")
225
- temp_results.append((keyword, 0, 0, 0, "Error"))
226
  results = temp_results
227
 
228
  return results
 
115
  try:
116
  data = api.get_keywords_data([keyword])
117
  if 'keywordList' in data and len(data['keywordList']) > 0:
118
+ # keywordList์—์„œ ์ž…๋ ฅํ•œ ํ‚ค์›Œ๋“œ์™€ ์ผ์น˜ํ•˜๋Š” ํ•ญ๋ชฉ์„ ์ฐพ์Šต๋‹ˆ๋‹ค.
119
+ for item in data['keywordList']:
120
+ if item['relKeyword'].strip().lower() == keyword.strip().lower():
121
+ monthly_pc = item.get('monthlyPcQcCnt', 0)
122
+ monthly_mobile = item.get('monthlyMobileQcCnt', 0)
123
+
124
+ if isinstance(monthly_pc, str):
125
+ monthly_pc = monthly_pc.replace(',', '').replace('< 10', '0')
126
+ try:
127
+ monthly_pc = int(monthly_pc)
128
+ except ValueError:
129
+ monthly_pc = 0
130
+ if isinstance(monthly_mobile, str):
131
+ monthly_mobile = monthly_mobile.replace(',', '').replace('< 10', '0')
132
+ try:
133
+ monthly_mobile = int(monthly_mobile)
134
+ except ValueError:
135
+ monthly_mobile = 0
136
+
137
+ total_searches = monthly_pc + monthly_mobile
138
+ return (keyword, monthly_pc, monthly_mobile, total_searches)
139
+ # ์ž…๋ ฅํ•œ ํ‚ค์›Œ๋“œ์™€ ์ผ์น˜ํ•˜๋Š” ํ•ญ๋ชฉ์ด ์—†์„ ๊ฒฝ์šฐ
140
+ return (keyword, 0, 0, 0)
141
  else:
142
  return (keyword, 0, 0, 0)
143
  except Exception as e:
 
223
  for future in blog_futures:
224
  try:
225
  keyword, blog_count = future.result()
226
+ temp_results.append((keyword, results[0][1], results[0][2], results[0][3], blog_count))
227
  except Exception as e:
228
  print(f"Error fetching blog count for keyword '{keyword}': {e}")
229
+ temp_results.append((keyword, results[0][1], results[0][2], results[0][3], "Error"))
230
  results = temp_results
231
 
232
  return results