|
@@ -1,7 +1,75 @@
|
|
|
|
|
+import json
|
|
|
|
|
+from pprint import pprint
|
|
|
|
|
+
|
|
|
from dotenv import load_dotenv
|
|
from dotenv import load_dotenv
|
|
|
import os
|
|
import os
|
|
|
-
|
|
|
|
|
|
|
+import random
|
|
|
|
|
+import requests
|
|
|
|
|
|
|
|
# Develop only
|
|
# Develop only
|
|
|
-load_dotenv()
|
|
|
|
|
-torn_api_key = os.environ('TORN_API_KEY')
|
|
|
|
|
|
|
+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 = "https://api.torn.com/user/4?selections=basic&key="
|
|
|
|
|
+ url = url+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 = json.loads(this_response.text)
|
|
|
|
|
+ return this_json
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _get_status():
|
|
|
|
|
+ this_json = _load_json()
|
|
|
|
|
+ this_status = this_json
|
|
|
|
|
+ # pprint(this_status)
|
|
|
|
|
+ status_return = None
|
|
|
|
|
+ if this_status:
|
|
|
|
|
+ status_return = this_status['status']
|
|
|
|
|
+ return status_return
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _from_roman_to_integer(roman_number):
|
|
|
|
|
+ integer = 0
|
|
|
|
|
+ if roman_number == 'I':
|
|
|
|
|
+ integer = 1
|
|
|
|
|
+ elif roman_number == 'II':
|
|
|
|
|
+ integer = 2
|
|
|
|
|
+ elif roman_number == 'III':
|
|
|
|
|
+ integer = 3
|
|
|
|
|
+ elif roman_number == 'IV':
|
|
|
|
|
+ integer = 4
|
|
|
|
|
+ elif roman_number == 'V':
|
|
|
|
|
+ integer = 5
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('Unknown Roman number: {}'.format(roman_number))
|
|
|
|
|
+ return integer
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def get_loot_level():
|
|
|
|
|
+ this_loot_level = 0
|
|
|
|
|
+ this_status = _get_status()
|
|
|
|
|
+ if this_status and len(this_status) > 1:
|
|
|
|
|
+ if this_status[0] == 'Okay' and 'Loot level' in this_status[1]:
|
|
|
|
|
+ this_loot_level = this_status[1][11:].strip()
|
|
|
|
|
+ # print(this_loot_level)
|
|
|
|
|
+ this_integer = _from_roman_to_integer(this_loot_level)
|
|
|
|
|
+ return this_loot_level,this_integer,this_status
|