-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrank_api_caller.py
More file actions
38 lines (27 loc) · 992 Bytes
/
rank_api_caller.py
File metadata and controls
38 lines (27 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
from fclty_tools import *
import requests
from bs4 import BeautifulSoup
from datetime import datetime, timedelta
from pytz import timezone
class RankCaller:
def __init__(self):
self.service_key = os.environ['KOPIS_SERVICE_KEY']
def get_rank(self):
yesterday = (datetime.now(timezone('Asia/Seoul')).date() - timedelta(1)).strftime("%Y%m%d")
url = "http://kopis.or.kr/openApi/restful/boxoffice"
params = {
'service': self.service_key,
'ststype': 'day',
'date': yesterday
}
response = requests.get(url, params=params).text
xmlobj = BeautifulSoup(response, 'lxml-xml').find_all("boxof")
list = []
for i in range(0, 10):
data = {}
data['performance_id'] = xmlobj[i].find("mt20id").string
data['rnum'] = xmlobj[i].find("rnum").string
data['basedate'] = yesterday
list.append(data)
return list