本文整理汇总了Python中config.config.Config.get_challonge_api_key方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get_challonge_api_key方法的具体用法?Python Config.get_challonge_api_key怎么用?Python Config.get_challonge_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.config.Config
的用法示例。
在下文中一共展示了Config.get_challonge_api_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConfig
# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_challonge_api_key [as 别名]
class TestConfig(unittest.TestCase):
def setUp(self):
self.config = Config(TEMPLATE_CONFIG_FILE)
def test_get_mongo_url(self):
self.assertEquals(self.config.get_mongo_url(), 'mongodb://USER:[email protected]/AUTH_DB')
def test_get_db_host(self):
self.assertEquals(self.config.get_db_host(), 'HOSTNAME')
def test_get_auth_db_name(self):
self.assertEquals(self.config.get_auth_db_name(), 'AUTH_DB')
def test_get_db_user(self):
self.assertEquals(self.config.get_db_user(), 'USER')
def test_get_db_password(self):
self.assertEquals(self.config.get_db_password(), 'PASSWORD')
def test_challonge_api_key(self):
self.assertEquals(self.config.get_challonge_api_key(), 'API_KEY')
def test_get_fb_app_id(self):
self.assertEquals(self.config.get_fb_app_id(), 'FB_APP_ID')
def test_get_fb_app_token(self):
self.assertEquals(self.config.get_fb_app_token(), 'FB_APP_TOKEN')
示例2: ChallongeScraper
# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_challonge_api_key [as 别名]
class ChallongeScraper(object):
def __init__(self, tournament_id):
self.tournament_id = tournament_id
self.config = Config(config_file_path=CONFIG_FILE_PATH)
self.api_key = self.config.get_challonge_api_key()
self.api_key_dict = {'api_key': self.api_key}
self.raw_dict = None
self.get_raw()
def get_raw(self):
if self.raw_dict == None:
self.raw_dict = {}
url = TOURNAMENT_URL % self.tournament_id
self.raw_dict['tournament'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
url = MATCHES_URL % self.tournament_id
self.raw_dict['matches'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
url = PARTICIPANTS_URL % self.tournament_id
self.raw_dict['participants'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
return self.raw_dict
def get_name(self):
return self.get_raw()['tournament']['tournament']['name'].strip()
def get_date(self):
return iso8601.parse_date(self.get_raw()['tournament']['tournament']['created_at'])
def get_matches(self):
player_map = dict((p['participant']['id'], p['participant']['name'].strip()
if p['participant']['name']
else p['participant']['username'].strip())
for p in self.get_raw()['participants'])
matches = []
for m in self.get_raw()['matches']:
m = m['match']
winner_id = m['winner_id']
loser_id = m['loser_id']
if winner_id is not None and loser_id is not None:
winner = player_map[winner_id]
loser = player_map[loser_id]
match_result = MatchResult(winner=winner, loser=loser)
matches.append(match_result)
return matches
def get_players(self):
return [p['participant']['name'].strip() if p['participant']['name'] else p['participant']['username'].strip() \
for p in self.get_raw()['participants']]
def _check_for_200(self, response):
if response.status_code != 200:
raise Exception('Received status code of %d' % response.status_code)
return response