|
| 1 | +import requests |
| 2 | +import json |
| 3 | +import time |
| 4 | +from dotenv import load_dotenv |
| 5 | +import os |
| 6 | + |
| 7 | +load_dotenv() |
| 8 | +SF_API_BULKS = os.getenv('SF_API_BULKS') |
| 9 | +headers = {'User-Agent': 'ScryFetcher/0.1', 'Accept': '*/*'} |
| 10 | + |
| 11 | +def get_dcbulk(): |
| 12 | + bulk_response = requests.get(SF_API_BULKS, headers=headers) |
| 13 | + print(f"bulk_response: {bulk_response}") |
| 14 | + time.sleep(0.1) |
| 15 | + |
| 16 | + bulk_response = bulk_response.json() |
| 17 | + response_data = bulk_response.get("data") |
| 18 | + dc_uri = response_data[2].get("uri") |
| 19 | + |
| 20 | + dc_response = requests.get(dc_uri, headers=headers) |
| 21 | + print(f"dc_response: {dc_response}") |
| 22 | + time.sleep(0.1) |
| 23 | + |
| 24 | + dc_response = dc_response.json() |
| 25 | + |
| 26 | + return dc_response |
| 27 | + |
| 28 | +def get_acbulk(): |
| 29 | + bulk_response = requests.get(SF_API_BULKS, headers=headers) |
| 30 | + print(f"bulk_response: {bulk_response}") |
| 31 | + time.sleep(0.1) |
| 32 | + |
| 33 | + bulk_response = bulk_response.json() |
| 34 | + response_data = bulk_response.get("data") |
| 35 | + ac_uri = response_data[3].get("uri") |
| 36 | + |
| 37 | + ac_response = requests.get(ac_uri, headers=headers) |
| 38 | + print(f"ac_response: {ac_response}") |
| 39 | + time.sleep(0.1) |
| 40 | + |
| 41 | + ac_response = ac_response.json() |
| 42 | + |
| 43 | + return ac_response |
| 44 | + |
| 45 | +def get_bulk_json(): |
| 46 | + bulk_response = requests.get(SF_API_BULKS, headers=headers) |
| 47 | + print(f"bulk_response: {bulk_response}") |
| 48 | + time.sleep(0.1) |
| 49 | + |
| 50 | + with open("./json_dump/misc/api_bulk.json", "w", encoding="utf-8") as outfile: |
| 51 | + outfile.write(bulk_response.text) |
| 52 | + |
| 53 | +def get_type_jsons(): |
| 54 | + SF_CATALOG_SUPER = os.getenv("SF_CATALOG_SUPER") |
| 55 | + SF_CATALOG_CARD = os.getenv("SF_CATALOG_CARD") |
| 56 | + SF_CATALOG_ARTIFACT = os.getenv("SF_CATALOG_ARTIFACT") |
| 57 | + SF_CATALOG_BATTLE = os.getenv("SF_CATALOG_BATTLE") |
| 58 | + SF_CATALOG_CREATURE = os.getenv("SF_CATALOG_CREATURE") |
| 59 | + SF_CATALOG_ENCHANTMENT = os.getenv("SF_CATALOG_ENCHANTMENT") |
| 60 | + SF_CATALOG_LAND = os.getenv("SF_CATALOG_LAND") |
| 61 | + SF_CATALOG_PLANESWALKER = os.getenv("SF_CATALOG_PLANESWALKER") |
| 62 | + SF_CATALOG_SPELL = os.getenv("SF_CATALOG_SPELL") |
| 63 | + |
| 64 | + supertype_res = requests.get(SF_CATALOG_SUPER, headers=headers) |
| 65 | + print(f"supertype_res: {supertype_res}") |
| 66 | + time.sleep(0.1) |
| 67 | + with open("./json_dump/misc/super_type.json", "w", encoding="utf-8") as outfile: |
| 68 | + outfile.write(supertype_res.text) |
| 69 | + |
| 70 | + cardtype_res = requests.get(SF_CATALOG_CARD, headers=headers) |
| 71 | + print(f"cardtype_res: {cardtype_res}") |
| 72 | + time.sleep(0.1) |
| 73 | + with open("./json_dump/misc/card_type.json", "w", encoding="utf-8") as outfile: |
| 74 | + outfile.write(cardtype_res.text) |
| 75 | + |
| 76 | + artifacttype_res = requests.get(SF_CATALOG_ARTIFACT, headers=headers) |
| 77 | + print(f"artifacttype_res: {artifacttype_res}") |
| 78 | + time.sleep(0.1) |
| 79 | + with open("./json_dump/misc/artifact_type.json", "w", encoding="utf-8") as outfile: |
| 80 | + outfile.write(artifacttype_res.text) |
| 81 | + |
| 82 | + battle_res = requests.get(SF_CATALOG_BATTLE, headers=headers) |
| 83 | + print(f"battle_res: {battle_res}") |
| 84 | + time.sleep(0.1) |
| 85 | + with open("./json_dump/misc/battle_type.json", "w", encoding="utf-8") as outfile: |
| 86 | + outfile.write(battle_res.text) |
| 87 | + |
| 88 | + creaturetype_res = requests.get(SF_CATALOG_CREATURE, headers=headers) |
| 89 | + print(f"creaturetype_res: {creaturetype_res}") |
| 90 | + time.sleep(0.1) |
| 91 | + with open("./json_dump/misc/creatue_type.json", "w", encoding="utf-8") as outfile: |
| 92 | + outfile.write(creaturetype_res.text) |
| 93 | + |
| 94 | + enchantmenttype_res = requests.get(SF_CATALOG_ENCHANTMENT, headers=headers) |
| 95 | + print(f"enchantmenttype_res: {enchantmenttype_res}") |
| 96 | + time.sleep(0.1) |
| 97 | + with open("./json_dump/misc/enchantment_type.json", "w", encoding="utf-8") as outfile: |
| 98 | + outfile.write(enchantmenttype_res.text) |
| 99 | + |
| 100 | + landtype_res = requests.get(SF_CATALOG_LAND, headers=headers) |
| 101 | + print(f"landtype_res: {landtype_res}") |
| 102 | + time.sleep(0.1) |
| 103 | + with open("./json_dump/misc/land_type.json", "w", encoding="utf-8") as outfile: |
| 104 | + outfile.write(landtype_res.text) |
| 105 | + |
| 106 | + planeswalkertype_res = requests.get(SF_CATALOG_PLANESWALKER, headers=headers) |
| 107 | + print(f"planeswalkertype_res: {planeswalkertype_res}") |
| 108 | + time.sleep(0.1) |
| 109 | + with open("./json_dump/misc/planeswalker_type.json", "w", encoding="utf-8") as outfile: |
| 110 | + outfile.write(planeswalkertype_res.text) |
| 111 | + |
| 112 | + spelltype_res = requests.get(SF_CATALOG_SPELL, headers=headers) |
| 113 | + print(f"spelltype_res: {spelltype_res}") |
| 114 | + time.sleep(0.1) |
| 115 | + with open("./json_dump/misc/spell_type.json", "w", encoding="utf-8") as outfile: |
| 116 | + outfile.write(spelltype_res.text) |
0 commit comments