Kims12 commited on
Commit
a024e59
ยท
verified ยท
1 Parent(s): 9c4b33c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -75,6 +75,13 @@ def get_blog_count(keyword):
75
  # ํด๋ผ์ด์–ธํŠธ ID์™€ ์‹œํฌ๋ฆฟ์„ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
76
  client_id = CLIENT_ID
77
  client_secret = CLIENT_SECRET
 
 
 
 
 
 
 
78
  encText = urllib.parse.quote(keyword)
79
  url = "https://openapi.naver.com/v1/search/blog?query=" + encText
80
  request = urllib.request.Request(url)
@@ -86,7 +93,7 @@ def get_blog_count(keyword):
86
  if rescode == 200:
87
  response_body = response.read()
88
  data = json.loads(response_body.decode('utf-8'))
89
- return data['total']
90
  else:
91
  return 0
92
  except Exception as e:
@@ -138,9 +145,17 @@ def get_monthly_search_volumes(keywords, include_related_keywords=True):
138
  monthly_mobile = item.get('monthlyMobileQcCnt', 0)
139
 
140
  if isinstance(monthly_pc, str):
141
- monthly_pc = int(monthly_pc.replace(',', '').replace('< 10', '0'))
 
 
 
 
142
  if isinstance(monthly_mobile, str):
143
- monthly_mobile = int(monthly_mobile.replace(',', '').replace('< 10', '0'))
 
 
 
 
144
 
145
  total_searches = monthly_pc + monthly_mobile
146
  results.append((keyword, monthly_pc, monthly_mobile, total_searches))
 
75
  # ํด๋ผ์ด์–ธํŠธ ID์™€ ์‹œํฌ๋ฆฟ์„ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
76
  client_id = CLIENT_ID
77
  client_secret = CLIENT_SECRET
78
+
79
+ # keyword๊ฐ€ ๋ฐ”์ดํŠธ ํƒ€์ž…์ผ ๊ฒฝ์šฐ ๋””์ฝ”๋”ฉ
80
+ if isinstance(keyword, bytes):
81
+ keyword = keyword.decode('utf-8')
82
+ elif not isinstance(keyword, str):
83
+ keyword = str(keyword)
84
+
85
  encText = urllib.parse.quote(keyword)
86
  url = "https://openapi.naver.com/v1/search/blog?query=" + encText
87
  request = urllib.request.Request(url)
 
93
  if rescode == 200:
94
  response_body = response.read()
95
  data = json.loads(response_body.decode('utf-8'))
96
+ return data.get('total', 0)
97
  else:
98
  return 0
99
  except Exception as e:
 
145
  monthly_mobile = item.get('monthlyMobileQcCnt', 0)
146
 
147
  if isinstance(monthly_pc, str):
148
+ monthly_pc = monthly_pc.replace(',', '').replace('< 10', '0')
149
+ try:
150
+ monthly_pc = int(monthly_pc)
151
+ except ValueError:
152
+ monthly_pc = 0
153
  if isinstance(monthly_mobile, str):
154
+ monthly_mobile = monthly_mobile.replace(',', '').replace('< 10', '0')
155
+ try:
156
+ monthly_mobile = int(monthly_mobile)
157
+ except ValueError:
158
+ monthly_mobile = 0
159
 
160
  total_searches = monthly_pc + monthly_mobile
161
  results.append((keyword, monthly_pc, monthly_mobile, total_searches))