Created
July 19, 2010 04:25
-
-
Save swdunlop/481012 to your computer and use it in GitHub Desktop.
This file contains 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
::: Misc ::: | |
Coat of Arms | |
Darksteel Colossus | |
Gargoyle Castle | |
Gorgon Flail | |
Howling Mine | |
Magebane Armor | |
Mirror of Fate | |
Pithing Needle | |
Rod of Ruin | |
Spellbook | |
::: Black ::: | |
Acolyte of Xathrid | |
Bog Wraith | |
Cemetery Reaper | |
Consume Spirit | |
Dread Warlock | |
Drudge Skeletons | |
Hypnotic Specter | |
Kelinore Bat | |
Looming Shade | |
Megrim | |
Mind Shatter | |
Nightmare | |
Sanguine Bond | |
Soul Bleed | |
Tendrils of Corruption | |
Underworld Dreams | |
Vampire Aristocrat | |
Vampire Nocturnus | |
Wall of Bone | |
Warpath Ghoul | |
Weakness | |
Xathrid Demon | |
Zombie Goliath | |
::: Blue ::: | |
Air Elemental | |
Convincing Mirage | |
Coral Merfolk | |
Disorient | |
Divination | |
Djinn of Wishes | |
Essence Scatter | |
Fabricate | |
Hive Mind | |
Horned Turtle | |
Illusionary Servant | |
Jump | |
Levitation | |
Merfolk Looter | |
Mind Spring | |
Phantom Warrior | |
Polymorph | |
Ponder | |
Sage Owl | |
Serpent of the Endless Sea | |
Snapping Drake | |
Sphinx Ambassador | |
Telepathy | |
Time Warp | |
Twincast | |
Wind Drake | |
Zephyr Sprite | |
::: Green ::: | |
Ant Queen | |
Borderland Ranger | |
Bountiful Harvest | |
Bramble Creeper | |
Centaur Courser | |
Craw Wurm | |
Deadly Recluse | |
Elvish Piper | |
Elvish Visionary | |
Emerald Oryx | |
Enormous Baloth | |
Entangling Vines | |
Great Sable Stag | |
Howl of the Night Pack | |
Kalonian Behemoth | |
Lurking Predators | |
Master of the Wild Hunt | |
Might of Oaks | |
Mist Leopard | |
Mold Adder | |
Oakenform | |
Overrun | |
Rampant Growth | |
Regenerate | |
Stampeding Rhino | |
Windstorm | |
::: Red ::: | |
Ball Lightning | |
Bogardan Hellkite | |
Burning Inquiry | |
Burst of Speed | |
Capricious Efreet | |
Dragon Whelp | |
Earthquake | |
Firebreathing | |
Goblin Artillery | |
Ignite Disorder | |
Inferno Elemental | |
Jackal Familiar | |
Kindled Fury | |
Lightning Elemental | |
Manabarbs | |
Panic Attack | |
Raging Goblin | |
Seismic Strike | |
Shatter | |
Shivan Dragon | |
Siege-Gang Commander | |
Sparkmage Apprentice | |
Stone Giant | |
Trumpet Blast | |
Viashino Spearhunter | |
Wall of Fire | |
Warp World | |
Yawning Fissure | |
::: White ::: | |
Angel's Mercy | |
Captain of the Watch | |
Divine Verdict | |
Glorious Charge | |
Griffin Sentinel | |
Guardian Seraph | |
Harm's Way | |
Indestructibility | |
Lifelink | |
Lightwielder Paladin | |
Mesa Enchantress | |
Open the Vaults | |
Planar Cleansing | |
Razorfoot Griffin | |
Rhox Pikemaster | |
Righteousness | |
Soul Warden | |
Tempest of Light | |
Undead Slayer | |
Veteran Armorsmith | |
Veteran Swordsmith | |
Wall of Faith |
This file contains 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
#!/usr/bin/env python | |
from urllib import quote as urlquote | |
from urllib2 import urlopen | |
import csv, re, sys | |
if len( sys.argv ) != 2: | |
print 'USAGE: fetch-set <Magic Set>' | |
print '' | |
print 'Fetches a CSV list of all cards in a given set from the Gatherer Database' | |
sys.exit( 1 ) | |
magic_set = sys.argv[1] | |
### Confirmed Viable, July 18, 2010 | |
re_entry = re.compile( | |
'<tr class="cardItem">' | |
'<td class="number">(.*?)</td>' | |
'<td class="name"><a class="nameLink" href=".*?">(.*?)</a></td>' | |
'<td class="artist">.*?</td>' | |
'<td class="color">(.*?)</td>' | |
'<td class="rarity">(.*?)</td>' | |
'.*?' | |
'</tr>' | |
) | |
### NOTE: This is Anglo-centric. | |
ignored_names = set(( | |
'Swamp', 'Plains', 'Forest', 'Mountains', 'Island' | |
)) | |
### Gets raw document from WotC to scrape. | |
html = urlopen( | |
'http://gatherer.wizards.com/Pages/Search/Default.aspx' | |
'?output=checklist&set=["%s"]' % urlquote( magic_set ) | |
).read( ) | |
### Brute force parsing beats Beautiful Soup any day of the week. | |
entries = re_entry.findall( html ) | |
if not entries: | |
print 'ERROR: Either WotC made a really small set this season, or the name is incorrect.' | |
sys.exit(2) | |
### Our CSV file | |
csv = csv.writer( open( magic_set + '.csv', 'w' ), dialect=csv.excel ) | |
for number, name, color, rarity in entries: | |
if name in ignored_names: continue | |
#print number, name, color, rarity | |
csv.writerow(( number, name, color, rarity )) |
This file contains 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
#!/usr/bin/env python | |
from urllib import quote as urlquote | |
from urllib2 import urlopen | |
import csv, sys, os.path | |
if len( sys.argv ) != 3: | |
print 'USAGE: find-orphans <Old Set> <New Set>' | |
print '' | |
print 'Given an original set, such as "Magic 2010", determines which cards are' | |
print 'no longer in the new set, such as "Magic 2011.' | |
print '' | |
print 'This is intended to be used with "fetch-set" to retrieve CSV files from' | |
print 'Wizards of the Coast and do the heavy work offline, please be' | |
print 'considerate of Wizards of the Coast and only retrieve sets that you' | |
print 'do not have.' | |
sys.exit( 1 ) | |
### Acquire the old CSV file path. | |
old_csv = sys.argv[1] | |
if not old_csv.lower( ).endswith( '.csv' ): old_csv += '.csv' | |
if not os.path.exists( old_csv ): | |
print 'Could not find the old set "%s."' % old_csv | |
sys.exit( 2 ) | |
### Acquire the new CSV file path. | |
new_csv = sys.argv[2] | |
if not new_csv.lower( ).endswith( '.csv' ): new_csv += '.csv' | |
if not os.path.exists( new_csv ): | |
print 'Could not find the new set "%s."' % new_csv | |
sys.exit( 2 ) | |
def compare_entries( x, y ): | |
return | |
### Collapse the names in the CSV files into a set. | |
old_set = dict( (entry[1], entry) for entry in csv.reader( open( old_csv, 'r' ) ) ) | |
new_set = dict( (entry[1], entry) for entry in csv.reader( open( new_csv, 'r' ) ) ) | |
### That which was in the old set, but not in the new set is an orphan. | |
orphans = list( entry for name, entry in old_set.iteritems( ) if name not in new_set ) | |
### Sort it out for the user. | |
def sort_fn( x, y ): | |
if x[2] < y[2]: | |
return -1 | |
elif x[2] > y[2]: | |
return +1 | |
elif x[1] < y[1]: | |
return -1 | |
elif x[1] == y[1]: | |
return 0 | |
else: | |
return +1 | |
if not orphans: | |
print 'Wizards must have been very sparing this year, as there were no orphans between the two.' | |
sys.exit(3) | |
orphans.sort( sort_fn ) | |
### And that which was orphaned, we need to know about so we can pull it out. | |
last_color = None | |
for number, name, color, rarity in orphans: | |
if color == '': | |
color = 'Misc' | |
if color != last_color: | |
if last_color: | |
print '::: %s :::' % color | |
last_color = color | |
print ' %s' % name | |
sys.exit( ) | |
if not entries: | |
print 'ERROR: Either WotC made a really small set this season, or the name is incorrect.' | |
sys.exit(2) | |
### Our CSV file | |
csv = csv.writer( open( magic_set + '.csv', 'w' ), dialect=csv.excel ) | |
for number, name, color, rarity in entries: | |
if name in ignored_names: continue | |
#print number, name, color, rarity | |
csv.writerow(( number, name, color, rarity )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment