smaller jsons (#673)
limited burn to only red cards and also added limited json files to only have fields needed to play
This commit is contained in:
parent
06feaa9ab0
commit
2836b11f2a
|
@ -18,10 +18,10 @@ def generate_initial_query(category):
|
||||||
elif category == 'wrath':
|
elif category == 'wrath':
|
||||||
string_query += 'otag%3Asweeper-creature+%28t%3Ainstant+or+t%3Asorcery%29+not%3Aadventure'
|
string_query += 'otag%3Asweeper-creature+%28t%3Ainstant+or+t%3Asorcery%29+not%3Aadventure'
|
||||||
elif category == 'burn':
|
elif category == 'burn':
|
||||||
string_query += '%28o%3A%2Fdamage+to+them%2F+or+%28o%3Adeals+o%3Adamage+o%3A%2Fcontroller%28%5C.%7C+%29%2F%29' \
|
string_query += '%28c>%3Dr+or+mana>%3Dr%29+%28o%3A%2Fdamage+to+them%2F+or+%28o%3Adeals+o%3Adamage+o%3A' \
|
||||||
'+or+o%3A%2F~+deals+%28.%7C..%29+damage+to+%28any+target%7C.%2Aplayer%28%5C.%7C+or' \
|
'%2Fcontroller%28%5C.%7C+%29%2F%29+or+o%3A%2F~+deals+%28.%7C..%29+damage+to+%28any+target%7C' \
|
||||||
'+planeswalker%29%7C.%2Aopponent%28%5C.%7C+or+planeswalker%29%29%2F%29+%28type%3Ainstant+or' \
|
'.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \
|
||||||
'+type%3Asorcery%29+not%3Aadventure'
|
'+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure'
|
||||||
# add category string query here
|
# add category string query here
|
||||||
string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \
|
string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \
|
||||||
'<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29' \
|
'<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29' \
|
||||||
|
@ -44,10 +44,48 @@ def fetch_and_write(category, query, count):
|
||||||
response = requests.get(f"{query}").json()
|
response = requests.get(f"{query}").json()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
with open('jsons/' + category + str(count) + '.json', 'w') as f:
|
with open('jsons/' + category + str(count) + '.json', 'w') as f:
|
||||||
json.dump(response, f)
|
json.dump(to_compact_write_form(response), f)
|
||||||
return response['has_more']
|
return response['has_more']
|
||||||
|
|
||||||
|
|
||||||
|
def to_compact_write_form(response):
|
||||||
|
fieldsToUse = ['has_more']
|
||||||
|
fieldsInCard = ['name', 'image_uris', 'content_warning', 'flavor_name', 'reprint', 'frame_effects', 'digital',
|
||||||
|
'set_type']
|
||||||
|
smallJson = dict()
|
||||||
|
data = []
|
||||||
|
# write all fields needed in response
|
||||||
|
for field in fieldsToUse:
|
||||||
|
smallJson[field] = response[field]
|
||||||
|
# write all fields needed in card
|
||||||
|
for card in response['data']:
|
||||||
|
write_card = dict()
|
||||||
|
for field in fieldsInCard:
|
||||||
|
if field == 'name' and 'card_faces' in card:
|
||||||
|
write_card['name'] = card['card_faces'][0]['name']
|
||||||
|
elif field == 'image_uris':
|
||||||
|
write_card['image_uris'] = write_image_uris(card['image_uris'])
|
||||||
|
elif field in card:
|
||||||
|
write_card[field] = card[field]
|
||||||
|
data.append(write_card)
|
||||||
|
smallJson['data'] = data
|
||||||
|
return smallJson
|
||||||
|
|
||||||
|
|
||||||
|
# only write images needed
|
||||||
|
def write_image_uris(card_image_uris):
|
||||||
|
image_uris = dict()
|
||||||
|
if 'normal' in card_image_uris:
|
||||||
|
image_uris['normal'] = card_image_uris['normal']
|
||||||
|
elif 'large' in card_image_uris:
|
||||||
|
image_uris['normal'] = card_image_uris['large']
|
||||||
|
elif 'small' in card_image_uris:
|
||||||
|
image_uris['normal'] = card_image_uris['small']
|
||||||
|
if card_image_uris:
|
||||||
|
image_uris['art_crop'] = card_image_uris['art_crop']
|
||||||
|
return image_uris
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for category in allCategories:
|
for category in allCategories:
|
||||||
print(category)
|
print(category)
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user