change vsCode settings for python

This commit is contained in:
marsteralex 2022-09-10 00:54:14 +02:00
parent c408c55086
commit fed6380af6
2 changed files with 63 additions and 30 deletions

View File

@ -9,5 +9,8 @@
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "ms-python.python"
}
}

View File

@ -3,7 +3,8 @@ import requests
import json
# add category name here
allCategories = ['counterspell', 'beast', 'burn', 'commander', 'artist'] #, 'terror', 'wrath', 'zombie', 'artifact']
# , 'terror', 'wrath', 'zombie', 'artifact']
allCategories = ['counterspell', 'beast', 'burn', 'commander', 'artist']
specialCategories = ['set', 'basic']
artists = dict()
@ -40,6 +41,7 @@ def generate_initial_query(category):
print(string_query)
return string_query
def generate_initial_special_query(category):
string_query = 'https://api.scryfall.com/cards/search?q='
if category == 'set':
@ -84,18 +86,19 @@ def fetch_and_write_all_special(category, query):
json.dump(all_cards, f)
def fetch(query, count):
query += str(count)
response = requests.get(f"{query}").json()
time.sleep(0.1)
return response
def fetch_special(query):
response = requests.get(f"{query}").json()
time.sleep(0.1)
return response
def write_art(art_names, id, index, digital):
if digital:
art_names[id] = index
@ -104,7 +107,8 @@ def write_art(art_names, id, index, digital):
def to_compact_write_form(smallJson, art_names, response, category):
fieldsInCard = ['name', 'image_uris', 'flavor_name', 'reprint', 'frame_effects', 'digital', 'set_type']
fieldsInCard = ['name', 'image_uris', 'flavor_name',
'reprint', 'frame_effects', 'digital', 'set_type']
data = []
# write all fields needed in card
for card in response['data']:
@ -115,17 +119,26 @@ def to_compact_write_form(smallJson, art_names, response, category):
if category == 'artist' and len(card['artist_ids']) != 1:
continue
# do not repeat art
digital_holder = False
digital_holder = -1
if 'card_faces' in card:
card_face = card['card_faces'][0]
if 'illustration_id' not in card_face or card_face['illustration_id'] in art_names and (art_names[card_face['illustration_id']] < 0 or card['digital']):
continue
else:
write_art(art_names, card_face['illustration_id'], len(data)+len(smallJson['data']), card['digital'])
elif 'illustration_id' not in card or card['illustration_id'] in art_names:
ind = len(data)+len(smallJson['data'])
if (card_face['illustration_id'] in art_names):
digital_holder = ind
ind = -1
write_art(
art_names, card_face['illustration_id'], ind, card['digital'])
elif 'illustration_id' not in card or card['illustration_id'] in art_names and (art_names[card['illustration_id']] < 0 or card['digital']):
continue
else:
write_art(art_names, card['illustration_id'], len(data)+len(smallJson['data']), card['digital'])
ind = len(data)+len(smallJson['data'])
if (card['illustration_id'] in art_names):
digital_holder = ind
ind = -1
write_art(art_names, card['illustration_id'], ind, card['digital'])
write_card = dict()
for field in fieldsInCard:
# if field == 'name' and category == 'artifact':
@ -140,14 +153,20 @@ def to_compact_write_form(smallJson, art_names, response, category):
write_card['name'] = card['card_faces'][0]['name']
elif field == 'image_uris':
if 'card_faces' in card and 'image_uris' in card['card_faces'][0]:
write_card['image_uris'] = write_image_uris(card['card_faces'][0]['image_uris'])
write_card['image_uris'] = write_image_uris(
card['card_faces'][0]['image_uris'])
else:
write_card['image_uris'] = write_image_uris(card['image_uris'])
write_card['image_uris'] = write_image_uris(
card['image_uris'])
elif field in card:
write_card[field] = card[field]
if digital_holder != -1:
data[digital_holder] = write_card
else:
data.append(write_card)
smallJson['data'] += data
def to_compact_write_form_special(smallJson, art_names, response, category):
fieldsInBasic = ['image_uris', 'set', 'set_type', 'digital']
data = []
@ -159,17 +178,27 @@ def to_compact_write_form_special(smallJson, art_names, response, category):
if category == 'basic':
write_card = dict()
# do not repeat art
if 'illustration_id' not in card or card['illustration_id'] in art_names:
digital_holder = -1
if 'illustration_id' not in card or card['illustration_id'] in art_names and (art_names[card['illustration_id']] < 0 or card['digital']):
continue
else:
write_art(art_names, card['illustration_id'], len(data)+len(smallJson['data']), card['digital'])
ind = len(data)+len(smallJson['data'])
if (card['illustration_id'] in art_names):
digital_holder = ind
ind = -1
write_art(
art_names, card['illustration_id'], ind, card['digital'])
for field in fieldsInBasic:
if field == 'image_uris':
write_card['image_uris'] = write_image_uris(card['image_uris'])
write_card['image_uris'] = write_image_uris(
card['image_uris'])
elif field == 'set':
write_card['name'] = card['set']
elif field in card:
write_card[field] = card[field]
if digital_holder != -1:
data[digital_holder] = write_card
else:
data.append(write_card)
else:
if card['set_type'] != 'token':
@ -198,7 +227,8 @@ if __name__ == "__main__":
fetch_and_write_all(category, generate_initial_query(category))
for category in specialCategories:
print(category)
fetch_and_write_all_special(category, generate_initial_special_query(category))
fetch_and_write_all_special(
category, generate_initial_special_query(category))
print("artistList")
with open('jsons/artistList.json', 'w') as f:
json.dump(artists, f)