import urllib.request
import urllib.error
import os
import json


def pull_jsons(version):
	local_cards = 'all_cards.json'
	local_sets = 'all_sets.json'
	
	try:
		print('trying https://mtgjson.com/' + version + '/json/AllCards.json ...')
		local_cards = urllib.request.urlretrieve('https://mtgjson.com/' + version + '/json/AllCards.json')
		# local_sets = urllib.request.urlretrieve('https://mtgjson.com/' + version + '/json/AllSets.json')
	except urllib.error.URLError as e:
		print(e.reason)

	try:
		with open(local_cards) as cards:
			print(cards.readline(3))
	except IOError as e:
		print(e)

pull_jsons('v4')
