| 123456789101112131415161718192021222324252627282930313233343536 |
- import json
- import os
- import random
- import requests
- from dotenv import load_dotenv
- # Develop only
- load_dotenv(verbose=True)
- def _get_api_key():
- torn_api_keys = json.loads(os.environ['TORN_API_KEY'])
- # pprint(torn_api_keys)
- torn_api_key = random.choice(torn_api_keys)
- # print(torn_api_key)
- return torn_api_key
- def _get_url():
- torn_api_key = _get_api_key()
- url = f"https://api.torn.com/torn/?selections=rackets&key={torn_api_key}"
- return url
- def _get_json():
- this_url = _get_url()
- response = requests.get(this_url)
- return response
- def load_json():
- this_response = _get_json()
- this_json = {}
- if this_response and this_response.text:
- this_json = json.loads(this_response.text)
- return this_json
|