model.py 767 B

123456789101112131415161718192021222324252627282930313233343536
  1. import json
  2. import os
  3. import random
  4. import requests
  5. from dotenv import load_dotenv
  6. # Develop only
  7. load_dotenv(verbose=True)
  8. def _get_api_key():
  9. torn_api_keys = json.loads(os.environ['TORN_API_KEY'])
  10. # pprint(torn_api_keys)
  11. torn_api_key = random.choice(torn_api_keys)
  12. # print(torn_api_key)
  13. return torn_api_key
  14. def _get_url():
  15. torn_api_key = _get_api_key()
  16. url = f"https://api.torn.com/torn/?selections=rackets&key={torn_api_key}"
  17. return url
  18. def _get_json():
  19. this_url = _get_url()
  20. response = requests.get(this_url)
  21. return response
  22. def load_json():
  23. this_response = _get_json()
  24. this_json = {}
  25. if this_response and this_response.text:
  26. this_json = json.loads(this_response.text)
  27. return this_json