: application programming interface
import requests, json
import pandas as pd
Client_ID, Client_Secret = "내 아이디", "내 시크릿"
# 2. document: url, params, headers
url = "https://openapi.naver.com/v1/datalab/search"
params = {
"startDate": "2021-07-01",
"endDate": "2022-07-31",
"timeUnit": "month",
# array(JSON): array를 json, 그니까 파이썬에서는 dict 타입으로 넣어라
"keywordGroups" : [
{"groupName": "파리바게트", "keywords": ["파리바게트", "파리바게뜨", "파리스바게트", "파리스바게뜨", "빠리바게트", "빠리바게뜨", "빠바", "파바", "Paris Baguette", "paris baguette"]},
{"groupName": "뚜레주르", "keywords": ["뚜레주르", "뚜레쥬르", "뜌레주르", "뜌레쥬르", "뚜주", "뚜쥬", "뜌쥬", "Tous Les Jours", " tous les jours"]},
]
}
headers = {
"Content-Type": "application/json",
"X-Naver-Client-Id": Client_ID,
"X-Naver-Client-Secret": Client_Secret
}
: 대부분 JSON 포맷으로 데이터를 보내줌
response = requests.post(url, json.dumps(params), headers = headers)
response
data = response.json()["results"]
df = pd.DataFrame({
"date": [period["period"] for period in data[0]["data"]],
"Paris_Baguette": [ratio["ratio"] for ratio in data[0]["data"]],
"Tous_Les_Jours": [ratio["ratio"] for ratio in data[1]["data"]],
})
df.plot(figsize = (20, 10))