瀏覽代碼

Initial commit

Foppe Hemminga 6 年之前
當前提交
0b7c6c4b50
共有 3 個文件被更改,包括 44 次插入0 次删除
  1. 6 0
      main.py
  2. 36 0
      model.py
  3. 2 0
      requirements.txt

+ 6 - 0
main.py

@@ -0,0 +1,6 @@
+import model
+from pprint import pprint
+
+if __name__ == '__main__':
+    res = model.load_json()
+    pprint(res)

+ 36 - 0
model.py

@@ -0,0 +1,36 @@
+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

+ 2 - 0
requirements.txt

@@ -0,0 +1,2 @@
+python-dotenv
+requests