Last active
August 29, 2015 14:15
-
-
Save milesrout/250a25260f7fd3b87f86 to your computer and use it in GitHub Desktop.
Find all legendary creatures with a particular colour identity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import * | |
colours = 'WUR' | |
def f(c): | |
return 'o:{' + str(c) + '}' | |
def g(c): | |
return c.lower() | |
def h(z): | |
q = list(z) | |
numcolours = len(filter(lambda x: len(x) != 0, q)) | |
if numcolours == 0: | |
return 'c:c' | |
elif numcolours == 1: | |
return 'c!' + ''.join(q) | |
return 'c!m' + ''.join(q) | |
queries = [] | |
for c in product({0,1}, repeat=len(colours)): | |
z = (g(colours[i]) if b else '' for (i, b) in enumerate(int(not x) for x in c)) | |
query = "cmc<4 t:legendary t:creature " + h(z) + ' ' | |
y = (f(colours[i]) if b else '' for (i, b) in enumerate(c)) | |
query += '(' + ' AND '.join(filter(lambda x: len(x) != 0, y)) + ')' | |
queries.append(query) | |
import httplib | |
import urllib | |
import re | |
for q in queries: | |
conn = httplib.HTTPConnection("magiccards.info") | |
url = urllib.quote(q) | |
conn.request("GET", "/query?q=" + url[:-3]) | |
r = conn.getresponse() | |
if not re.search('Your query did not match any cards.', r.read()): | |
print(q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment