api.py 1003 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import requests
  2. from functools import wraps
  3. import logging
  4. logger = logging.getLogger(__name__)
  5. GAMEDATA_URL = 'https://ow.blizzard.cn/action/career/profile/gamedata'
  6. CAREER_URL = 'https://ow.blizzard.cn/action/career/profile'
  7. def bnet_api(func):
  8. @wraps(func)
  9. def decorated(*args, **kwargs):
  10. resp = func(*args, **kwargs)
  11. if resp.status_code != 200:
  12. logger.info('call [%s] failed, 200, args:[%s] [%s]', func.__name__, args, kwargs)
  13. return False
  14. json = resp.json()
  15. if json.get('status'):
  16. if json['status'] != 'success':
  17. logger.info('call [%s] failed, status non-success , args:[%s] [%s]', func.__name__, args, kwargs)
  18. return False
  19. return json['data']
  20. return json
  21. return decorated
  22. @bnet_api
  23. def get_gamedata():
  24. return requests.get(GAMEDATA_URL)
  25. @bnet_api
  26. def get_profile(cred):
  27. return requests.get(CAREER_URL, cookies={
  28. 'bnet_user_cred': cred
  29. })