Update app.py
Browse files
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
|
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 =
|
|
|
|
|
|
|
|
|
142 |
if isinstance(monthly_mobile, str):
|
143 |
-
monthly_mobile =
|
|
|
|
|
|
|
|
|
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))
|