Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze Cube Drafts - Fix get request for Scryfall API #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions article1_analyze_cube_drafts/analyze_decklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def fetch_cards():
'''Fetches the default cards from Scryfall'''

print('Fetching cards from Scryfall...')
resp = requests.get('https://archive.scryfall.com/json/scryfall-default-cards.json')
json_data = resp.json()
resp = requests.get('https://api.scryfall.com/bulk-data/default-cards')
download_uri = resp.json()["download_uri"]
json_data = requests.get(download_uri).json()

magic_cards = {}
for i in range(len(json_data)):
card_name = json_data[i]['name']
Expand Down Expand Up @@ -173,7 +175,7 @@ def export_card_analysis(deck_list_dict, magic_cards, card_filter, archetype_dic
# store the results of the card analysis in a dataframe. Then calculate win %, apply filter, and export to csv.
results = {card: {key: card_dict[card][key] for key in ['win', 'loss', 'num', 'color', 'cmc', 'type', 'main %', 'win %', 'win %/arch %']} for card in card_dict.keys()}
results_df = pd.DataFrame.from_dict(results, orient = 'index').reset_index()
results_df.columns = ['Name','Win', 'Loss','Num','Color', 'CMC', 'Type', 'Main %', 'Win %', 'Win %/Arch %']
results_df.columns = ['Name', 'Win', 'Loss','Num','Color', 'CMC', 'Type', 'Main %', 'Win %', 'Win %/Arch %']

if card_filter:
results_df = results_df.loc[results_df['Num'] > card_filter]
Expand Down Expand Up @@ -345,4 +347,4 @@ def main():
plot_timecourse(archetypes, timecourse)

if __name__ == '__main__':
main()
main()