-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommunicator.py
53 lines (36 loc) · 1.5 KB
/
communicator.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# coding=UTF-8
import urllib2
import requests
import json
from base64 import standard_b64encode
import const
import settings
SBL_STATS_URL = settings.SBL_STATS_URL
ENTRY_POINT = settings.ENTRY_POINT
#USERNAME = settings.USERNAME
#PASSWORD = settings.PASSWORD
#BASIC_AUTH_PLAIN = '%s:%s' % (USERNAME, PASSWORD)
#BASIC_AUTH_BASE64 = 'Basic %s' % standard_b64encode(BASIC_AUTH_PLAIN)
class SblCommunicator():
def __init__(self, league, season, stage, is_debug=False):
self.league_id = const.league_id_table[league]
self.stage_id = const.stage_id_table[league][season][stage]
self.is_debug = is_debug
def pretty_print_req(self, req):
print('{}\n{}\n{}\n\n{}'.format(
'-----------START-----------',
req.method + ' ' + req.url,
'\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()),
req.data
))
def endpoint(self, resource, item=None):
if item:
return '%s/%s/%s/' % (ENTRY_POINT, resource, item)
return '%s/%s/' % (ENTRY_POINT, resource)
def get_games_result(self):
payload = {'Mo': 9023, 'Type': 'basketball_stagematchlist', 'Nbr': self.stage_id, 'TagName': 'bbstagematchlist', 'DivId': 'bbstagematchlist'}
data = {'rs': 'sajaxSubmit', 'rsargs[]': '<Input><F><K></K><V></V></F></Input>'}
r = requests.post(SBL_STATS_URL, params=payload, data=data)
r.raise_for_status()
r.encoding = settings.ENCODE
return r.text