api.py 609 B

12345678910111213141516171819202122
  1. #!/usr/bin/python3
  2. import toml
  3. import requests
  4. try:
  5. config = toml.load("config/default.toml")
  6. except IOError as e:
  7. print(
  8. "No config file found. Please copy config/example.toml to "
  9. "config/default.toml and add your Blizzard API key. If you "
  10. "don't have one yet, you can register for one here: "
  11. "https://dev.battle.net/"
  12. )
  13. raise e
  14. def get_json(method, **kwargs):
  15. params = dict(config['api'])
  16. params['method'] = method
  17. params.update(kwargs)
  18. r = requests.get("{url}{method}?locale={locale}&apiKey={key}".format(**params))
  19. return r.json()