- Fixed MP3 play bug on the psp. MP3 files need to have NO Id3v2 tag, or they won't play. Also, volume control is broken
- added dt to moving W's easter egg movement.
- Added fullscreen for windows version
- other stuff ?
This commit is contained in:
wagic.the.homebrew
2008-11-19 12:21:23 +00:00
parent 2434571fa2
commit 349de34106
27 changed files with 1270 additions and 1012 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ ASFLAGS = $(CXXFLAGS)
INCDIR = ../../JGE/include ../../JGE/include/psp ../../JGE/include/psp/freetype2 ../../JGE/src
LIBDIR = ../../JGE/lib/psp
LDFLAGS =
LIBS = -ljge300 -lhgetools -lfreetype -ljpeg -lgif -lpng -lz -lm -lmikmod -lpsppower -lpspmpeg -lpspaudiocodec -lpspaudiolib -lpspaudio -lpspgum -lpspgu -lpsprtc -lstdc++ -lpspfpu
LIBS = -ljge300 -lhgetools -lfreetype -ljpeg -lgif -lpng -lz -lm -lmikmod -lpsppower -lpspmpeg -lpspaudiocodec -lpspaudiolib -lpspaudio -lpspmp3 -lpspgum -lpspgu -lpsprtc -lstdc++ -lpspfpu
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = WTH?!
+50 -50
View File
@@ -1,50 +1,50 @@
100
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
100
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+92 -92
View File
@@ -1,92 +1,92 @@
1167
460
1202
525
1340
92
1284
101
1149
20
1264
20
1321
20
1272
437
1126
485
1334
107
1352
91
1279
20
1154
481
1328
551
1335
20
1227
500
1236
489
1186
20
1219
20
1175
459
1136
111
1332
545
1250
21
1204
19
1381
499
1170
484
1097
102
1102
46
1282
485
1378
490
1300
20
1363
495
129665
90
1387
4
129652
5
174957
108
175030
5
130378
107
175031
5
1312
19
130386
97
1275
21
1148
103
135185
20
1100
109
153441
19
1167
460
1202
525
1340
92
1284
101
1149
20
1264
20
1321
20
1272
437
1126
485
1334
107
1352
91
1279
20
1154
481
1328
551
1335
20
1227
500
1236
489
1186
20
1219
20
1175
459
1136
111
1332
545
1250
21
1204
19
1381
499
1170
484
1097
102
1102
46
1282
485
1378
490
1300
20
1363
495
129665
90
1387
4
129652
5
174957
108
175030
5
130378
107
175031
5
1312
19
130386
97
1275
21
1148
103
135185
20
1100
109
153441
19
+1
View File
@@ -80,6 +80,7 @@ class GameApp: public JApp
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
static JMusic* music;
};
+11 -4
View File
@@ -194,9 +194,13 @@ class GameStateDeckViewer: public GameState, public JGuiListener
welcome_menu->Add(10, "Cancel");
if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
if (!bgMusic) bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/Track1.mp3");
if (bgMusic){
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
if (GameApp::music){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
GameApp::music = JSoundSystem::GetInstance()->LoadMusic("sound/track1.mp3");
if (GameApp::music){
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
}
}
colorFilter = ALL_COLORS;
@@ -219,7 +223,10 @@ class GameStateDeckViewer: public GameState, public JGuiListener
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic) JSoundSystem::GetInstance()->StopMusic(bgMusic);
if (GameApp::music){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
SAFE_DELETE(backTex);
SAFE_DELETE(backQuad);
SAFE_DELETE(welcome_menu);
+27 -20
View File
@@ -43,7 +43,7 @@ class GameStateMenu: public GameState, public JGuiListener
JQuad * mMovingW;
float mCreditsYPos;
int currentState;
JMusic * bgMusic;
//JMusic * bgMusic;
int mVolume;
char nbcardsStr[400];
@@ -64,10 +64,11 @@ class GameStateMenu: public GameState, public JGuiListener
mGuiController = NULL;
subMenuController = NULL;
mIconsTexture = NULL;
bgMusic = NULL;
//bgMusic = NULL;
timeIndex = 0;
angleMultiplier = MIN_ANGLE_MULTIPLIER;
yW = 55;
mVolume = 0;
}
virtual ~GameStateMenu()
@@ -90,7 +91,7 @@ class GameStateMenu: public GameState, public JGuiListener
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/menutitle.png", TEX_TYPE_USE_VRAM);
movingWTexture = JRenderer::GetInstance()->LoadTexture("graphics/movingW.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 0, 0, 256, 167); // Create background quad for rendering.
mBg = NEW JQuad(bgTexture, 0, 0, 256, 166); // Create background quad for rendering.
mMovingW = NEW JQuad(movingWTexture, 2, 2, 84, 62);
mBg->SetHotSpot(105,50);
mMovingW->SetHotSpot(72,16);
@@ -149,7 +150,7 @@ class GameStateMenu: public GameState, public JGuiListener
if (mBg) delete mBg;
if (mMovingW) delete mMovingW;
SAFE_DELETE (bgMusic);
//SAFE_DELETE (bgMusic);
}
@@ -157,15 +158,17 @@ class GameStateMenu: public GameState, public JGuiListener
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
if (GameApp::HasMusic && !bgMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/Track0.mp3");
if (GameApp::HasMusic && !GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
GameApp::music = JSoundSystem::GetInstance()->LoadMusic("sound/Track0.mp3");
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
}
if (bgMusic){
mVolume = 0;
JSoundSystem::GetInstance()->SetVolume(mVolume);
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
if (GameApp::HasMusic && GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] == 0){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
}
@@ -198,19 +201,23 @@ class GameStateMenu: public GameState, public JGuiListener
{
//mEngine->EnableVSync(false);
if (bgMusic)
{
JSoundSystem::GetInstance()->StopMusic(bgMusic);
}
// if (bgMusic)
// {
//JSoundSystem::GetInstance()->StopMusic(bgMusic);
//SAFE_DELETE(bgMusic);
// }
JRenderer::GetInstance()->EnableVSync(false);
}
virtual void Update(float dt)
{
if (bgMusic && mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
if (GameApp::music){
/*if (mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
}*/
}
timeIndex += dt * 2;
@@ -282,7 +289,7 @@ class GameStateMenu: public GameState, public JGuiListener
if (mEngine->GetButtonState(PSP_CTRL_TRIANGLE) && (dt != 0))
{
angleMultiplier = (cos(timeIndex)*angleMultiplier - M_PI/3 - 0.1 - angleW) / dt;
yW = yW + 0.001 + (yW - 55) / 1000;
yW = yW + 5*dt + (yW - 55) *5* dt;
}
else
angleW = cos(timeIndex)*angleMultiplier - M_PI/3 - 0.1;
@@ -290,7 +297,7 @@ class GameStateMenu: public GameState, public JGuiListener
else
{
angleW += angleMultiplier * dt;
yW = yW + 0.001 + (yW - 55) / 1000;
yW = yW + 5*dt + (yW - 55) *5*dt;
}
}
+2
View File
@@ -6,6 +6,8 @@
#endif
#ifdef _DEBUG
//if you get the following error :'_NORMAL_BLOCK' : undeclared identifier,
// try to add #include "crtdbg.h" somewhere in your code before including this file
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define NEW new
+2
View File
@@ -21,6 +21,7 @@ const char * const GameState::menuTexts[]= {"--NEW--","Deck 1", "Deck 2", "Deck
JResourceManager* GameApp::CommonRes = NEW JResourceManager();
hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL};
int GameApp::HasMusic = 1;
JMusic * GameApp::music = NULL;
GameState::GameState(GameApp* parent): mParent(parent)
{
@@ -75,6 +76,7 @@ void GameApp::Create()
}
CommonRes->CreateTexture("graphics/menuicons.png");
//Creating thes quad in this specific order allows us to have them in the correct order to call them by integer id
CommonRes->CreateQuad("c_artifact", "graphics/menuicons.png", 2 + 6*36, 38, 32, 32);
+9 -2
View File
@@ -181,6 +181,11 @@ void GameStateDuel::Update(float dt)
}
}else if (mGamePhase == DUEL_PLAY){
//Stop the music before starting the game
if (GameApp::music){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
@@ -209,11 +214,13 @@ void GameStateDuel::Update(float dt)
}else{
mGamePhase = DUEL_END;
}
}else if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
}else
#endif
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
End();
Start();
}
#endif
mFont->SetColor(ARGB(255,255,255,255));
}
if (mEngine->GetButtonClick(PSP_CTRL_START)){
+188 -188
View File
@@ -1,188 +1,188 @@
#!/usr/bin/python
#
# Requires BeautifulSoup verion 3, available from
# http://www.crummy.com/software/BeautifulSoup/
#
# Usage: python gatherer-builder.py <output file>
#
# Copyright 2006: Nathan Callahan
# Feel free to do what you want with this file, but give credit
# where it's due.
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag
import re
import codecs
import sys
import urllib
import os
import os.path
from mtgCommon import *
setinfo=sets['SHM']
stripReminderText = False
conffile = open(setinfo['dir'] + ".conf", 'w')
# FETCH_IMAGES = False
FETCH_IMAGES = True
url = "http://ww2.wizards.com/gatherer/Index.aspx?setfilter=%s\\&output=Spoiler" % setinfo['gathname']
gatherer = urllib.urlopen(url)
soup = BeautifulSoup(gatherer.read(), smartQuotesTo=None)
xml = BeautifulStoneSoup('<?xml version=\'1.0\' encoding=\'latin1\'?><!DOCTYPE ccg-setinfo SYSTEM "../gccg-set.dtd"><ccg-setinfo name="%s" dir="%s" abbrev="%s" game="Magic The Gathering"><cards></cards></ccg-setinfo>' % (setinfo['name'], setinfo['dir'], setinfo['abbrev']),selfClosingTags=['attr'])
rarity_re=re.compile(".*%s_(?P<rarity>.)\.gif.*" % setinfo['gathabbrev'])
def fetchImage(id, filename):
if (not os.path.exists(setinfo['abbrev'] + "/" + filename)):
for i in setinfo['gathdirs']:
url="http://resources.wizards.com/Magic/Cards/%s/Card%s.jpg" % (i, id)
print url
try:
pic = urllib.urlopen(url)
except:
pass
if (not pic): # this is completely wrong, supposed to check if it's not found
raise IOError
if (not os.path.exists(setinfo['abbrev'])):
os.mkdir(setinfo['abbrev'])
else:
assert os.path.isdir(setinfo['abbrev'])
f = open(setinfo['abbrev'] + "/" + filename, 'wb')
f.write(pic.read())
f.close()
for cardRow in soup.find(id="_gridResults").findAll('tr',onmouseover="this.style.backgroundColor='#F5DEB3';"):
name = cardRow('b')[0].string
name = name.replace('"','')
name = name.replace(u'\xe2', 'a')
name = name.replace(u'\xc6', 'AE')
manaCost = replaceSymbols(cardRow('td')[1]('font')[0])
manaCost = ''.join(manaCost.contents)
print manaCost
if manaCost == "&nbsp;":
manaCost="";
htmlText = cardRow('td')[3]
htmlText = replaceSymbols(htmlText)
text = cleanupHTMLText(htmlText, stripReminderText)
supertype, subtype = getCardTypes(cardRow)
splitCard = split_re.match(text)
if splitCard:
text = splitCard.group('t1') + " // " + splitCard.group('t2')
manaCost = manaCost + " // " + splitCard.group('mana2')
supertype = supertype + " // " + splitCard.group('type2')
power = cardRow('td')[4]('font')[0].string
if power == "&nbsp;":
power = None
toughness = cardRow('td')[5]('font')[0].string
if toughness == "&nbsp;":
toughness = None
colors = set()
for c in manaCost:
if c in symbolColors:
colors.add(symbolColors[c].capitalize())
color = ''.join(sorted([c+" " for c in colors])).rstrip()
if not color:
if (supertype.find("Artifact") != -1):
color = "Artifact"
elif (supertype.find("Land") != -1):
color = "Land"
else:
ss = "%s is " % name
start = text.find(ss) + len(ss)
end = text.find('.',start)
color = text[start:end].capitalize()
printings = 1
for printing in cardRow('td')[6].findAll(src=rarity_re):
print name
if name in basic_lands:
rarity = 'L'
else:
rarity = rarity_re.match(str(printing)).group('rarity')
card = Tag(xml, 'card')
cards=xml('ccg-setinfo')[0]('cards')[0]
cards.insert(len(cards),card)
card=cards('card')[-1]
card['name']=name
if printings > 1:
card['graphics']=name.translate(imagetrans)+str(printings)+".jpg"
else:
card['graphics']=name.translate(imagetrans)+".jpg"
id = id_re.match(printing.parent['onclick']).group('id')
if FETCH_IMAGES:
fetchImage(id, id + ".jpg")
text = text.replace(u'\xe2', 'a')
card['text']=text
card.insert(0,Tag(xml,'attr'))
card('attr')[0]['key']='rarity'
card('attr')[0]['value']=rarity
card.insert(1,Tag(xml,'attr'))
card('attr')[1]['key']='color'
card('attr')[1]['value']=color
conffile.write("[card]")
# conffile.write("\nimage=" + card['graphics'])
conffile.write("\ntext=" + text)
conffile.write("\nid=" + id)
conffile.write("\nname=" + name)
conffile.write("\nrarity=" + rarity)
# conffile.write("\ncolor=" + color)
conffile.write("\ntype=" + supertype)
if manaCost:
card.insert(2,Tag(xml,'attr'))
card('attr')[2]['key']='cost'
card('attr')[2]['value']=manaCost
conffile.write("\nmana=" + manaCost)
if power:
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='power'
card('attr')[-1]['value']=power
conffile.write("\npower=" + power)
if subtype:
subtype = subtype.replace(u'\xe2', 'a')
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='subtype'
card('attr')[-1]['value']=subtype
conffile.write("\nsubtype=" + subtype)
if toughness:
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='toughness'
card('attr')[-1]['value']=toughness
conffile.write("\ntoughness=" + toughness)
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='type'
card('attr')[-1]['value']=supertype
printings += 1
conffile.write("\n[/card]\n")
f = file(sys.argv[1],'w')
f.write(xml.prettify('latin1'))
f.close()
conffile.close()
#!/usr/bin/python
#
# Requires BeautifulSoup verion 3, available from
# http://www.crummy.com/software/BeautifulSoup/
#
# Usage: python gatherer-builder.py <output file>
#
# Copyright 2006: Nathan Callahan
# Feel free to do what you want with this file, but give credit
# where it's due.
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag
import re
import codecs
import sys
import urllib
import os
import os.path
from mtgCommon import *
setinfo=sets['CK']
stripReminderText = False
conffile = open(setinfo['dir'] + ".conf", 'w')
# FETCH_IMAGES = False
FETCH_IMAGES = True
url = "http://ww2.wizards.com/gatherer/Index.aspx?setfilter=%s\\&output=Spoiler" % setinfo['gathname']
gatherer = urllib.urlopen(url)
soup = BeautifulSoup(gatherer.read(), smartQuotesTo=None)
xml = BeautifulStoneSoup('<?xml version=\'1.0\' encoding=\'latin1\'?><!DOCTYPE ccg-setinfo SYSTEM "../gccg-set.dtd"><ccg-setinfo name="%s" dir="%s" abbrev="%s" game="Magic The Gathering"><cards></cards></ccg-setinfo>' % (setinfo['name'], setinfo['dir'], setinfo['abbrev']),selfClosingTags=['attr'])
rarity_re=re.compile(".*%s_(?P<rarity>.)\.gif.*" % setinfo['gathabbrev'])
def fetchImage(id, filename):
if (not os.path.exists(setinfo['abbrev'] + "/" + filename)):
for i in setinfo['gathdirs']:
url="http://resources.wizards.com/Magic/Cards/%s/Card%s.jpg" % (i, id)
print url
try:
pic = urllib.urlopen(url)
except:
pass
if (not pic): # this is completely wrong, supposed to check if it's not found
raise IOError
if (not os.path.exists(setinfo['abbrev'])):
os.mkdir(setinfo['abbrev'])
else:
assert os.path.isdir(setinfo['abbrev'])
f = open(setinfo['abbrev'] + "/" + filename, 'wb')
f.write(pic.read())
f.close()
for cardRow in soup.find(id="_gridResults").findAll('tr',onmouseover="this.style.backgroundColor='#F5DEB3';"):
name = cardRow('b')[0].string
name = name.replace('"','')
name = name.replace(u'\xe2', 'a')
name = name.replace(u'\xc6', 'AE')
manaCost = replaceSymbols(cardRow('td')[1]('font')[0])
manaCost = ''.join(manaCost.contents)
print manaCost
if manaCost == "&nbsp;":
manaCost="";
htmlText = cardRow('td')[3]
htmlText = replaceSymbols(htmlText)
text = cleanupHTMLText(htmlText, stripReminderText)
supertype, subtype = getCardTypes(cardRow)
splitCard = split_re.match(text)
if splitCard:
text = splitCard.group('t1') + " // " + splitCard.group('t2')
manaCost = manaCost + " // " + splitCard.group('mana2')
supertype = supertype + " // " + splitCard.group('type2')
power = cardRow('td')[4]('font')[0].string
if power == "&nbsp;":
power = None
toughness = cardRow('td')[5]('font')[0].string
if toughness == "&nbsp;":
toughness = None
colors = set()
for c in manaCost:
if c in symbolColors:
colors.add(symbolColors[c].capitalize())
color = ''.join(sorted([c+" " for c in colors])).rstrip()
if not color:
if (supertype.find("Artifact") != -1):
color = "Artifact"
elif (supertype.find("Land") != -1):
color = "Land"
else:
ss = "%s is " % name
start = text.find(ss) + len(ss)
end = text.find('.',start)
color = text[start:end].capitalize()
printings = 1
for printing in cardRow('td')[6].findAll(src=rarity_re):
print name
if name in basic_lands:
rarity = 'L'
else:
rarity = rarity_re.match(str(printing)).group('rarity')
card = Tag(xml, 'card')
cards=xml('ccg-setinfo')[0]('cards')[0]
cards.insert(len(cards),card)
card=cards('card')[-1]
card['name']=name
if printings > 1:
card['graphics']=name.translate(imagetrans)+str(printings)+".jpg"
else:
card['graphics']=name.translate(imagetrans)+".jpg"
id = id_re.match(printing.parent['onclick']).group('id')
if FETCH_IMAGES:
fetchImage(id, id + ".jpg")
text = text.replace(u'\xe2', 'a')
card['text']=text
card.insert(0,Tag(xml,'attr'))
card('attr')[0]['key']='rarity'
card('attr')[0]['value']=rarity
card.insert(1,Tag(xml,'attr'))
card('attr')[1]['key']='color'
card('attr')[1]['value']=color
conffile.write("[card]")
# conffile.write("\nimage=" + card['graphics'])
conffile.write("\ntext=" + text)
conffile.write("\nid=" + id)
conffile.write("\nname=" + name)
conffile.write("\nrarity=" + rarity)
# conffile.write("\ncolor=" + color)
conffile.write("\ntype=" + supertype)
if manaCost:
card.insert(2,Tag(xml,'attr'))
card('attr')[2]['key']='cost'
card('attr')[2]['value']=manaCost
conffile.write("\nmana=" + manaCost)
if power:
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='power'
card('attr')[-1]['value']=power
conffile.write("\npower=" + power)
if subtype:
subtype = subtype.replace(u'\xe2', 'a')
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='subtype'
card('attr')[-1]['value']=subtype
conffile.write("\nsubtype=" + subtype)
if toughness:
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='toughness'
card('attr')[-1]['value']=toughness
conffile.write("\ntoughness=" + toughness)
card.insert(len(card),Tag(xml,'attr'))
card('attr')[-1]['key']='type'
card('attr')[-1]['value']=supertype
printings += 1
conffile.write("\n[/card]\n")
f = file(sys.argv[1],'w')
f.write(xml.prettify('latin1'))
f.close()
conffile.close()
+495 -494
View File
@@ -1,494 +1,495 @@
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag
import re
import codecs
import sys
sets ={'BE':{'name':'Beta',
'dir':'BE',
'abbrev':'BE',
'gathabbrev': '2E',
'gathname':'LimitedEditionBeta',
},
'RV':{'name':'Revised',
'dir':'RV',
'abbrev':'RV',
'gathdirs':['3E/en-us'],
'gathabbrev': '3E',
'gathname':'RevisedEdition'
},
'4E':{'name':'4th Edition',
'dir':'4E',
'abbrev':'4E',
'gathdirs':['4E/en-us'],
'gathabbrev': '4E',
'gathname':'FourthEdition',
},
'5E':{'name':'5th Edition',
'dir':'5E',
'abbrev':'5E',
'gathdirs':['5E/en-us'],
'gathabbrev': '5E',
'gathname':'FifthEdition'
},
'6E':{'name':'6th Edition',
'dir':'6E',
'abbrev':'6E',
'gathdirs':['6E/en-us'],
'gathabbrev': '6E',
'gathname':'ClassicSixthEdition',
},
'7E':{'name':'7th Edition',
'dir':'7E',
'abbrev':'7E',
'gathdirs':['7E/en-us'],
'gathabbrev': '7E',
'gathname':'SeventhEdition',
},
'8E':{'name':'8th Edition',
'dir':'8E',
'abbrev':'8E',
'gathdirs':['8ED/en-us'],
'gathabbrev': '8ED',
'gathname':'EighthEdition',
},
'9E':{'name':'9th Edition',
'dir':'9E',
'abbrev':'9E',
'gathdirs':['9ED/en-us'],
'gathabbrev': '9ED',
'gathname':'NinthEdition',
},
'10E':{'name':'10th Edition',
'dir':'10E',
'abbrev':'10E',
'gathdirs':['10E/EN'],
'gathabbrev': '10E',
'gathname':'TenthEdition',
},
'EVE':{'name':'Eventide',
'dir':'EVE',
'abbrev':'EVE',
'gathdirs':['EVE/EN'],
'gathabbrev': 'EVE',
'gathname':'Eventide',
},
'SHM':{'name':'Shadowmoor',
'dir':'SHM',
'abbrev':'SHM',
'gathdirs':['SHM/EN'],
'gathabbrev': 'SHM',
'gathname':'Shadowmoor',
},
'ALA':{'name':'Shards of Alara',
'dir':'ALA',
'abbrev':'ALA',
'gathdirs':['ALA/EN'],
'gathabbrev': 'ALA',
'gathname':'ShardsOfAlara',
},
'UH':{'name':'Unhinged',
'dir':'UH',
'abbrev':'UH',
'gathdirs':['UNH/en-us'],
'gathabbrev': 'UNH',
'gathname':'Unhinged',
},
'UG':{'name':'Unglued',
'dir':'UG',
'abbrev':'UG',
'gathdirs':['UG/en-us'],
'gathabbrev':'UG',
'gathname':'Unglued',
},
'P1':{'name':'Portal',
'dir':'P1',
'abbrev':'P1',
'gathdirs':['P1/en-us'],
'gathabbrev':'P1',
'gathname':'Portal',
},
'P2':{'name':'Portal Second Age',
'dir':'P2',
'abbrev':'P2',
'gathdirs':['P2/en-us'],
'gathabbrev':'P2',
'gathname':'PortalSecondAge',
},
'P3':{'name':'Portal Three Kingdoms',
'dir':'P3',
'abbrev':'P3',
'gathdirs':['PK/en-us'],
'gathabbrev': 'PK',
'gathname':'PortalThreeKingdoms',
},
'AN':{'name':'Arabian Nights',
'dir':'AN',
'abbrev':'AN',
'gathdirs':['AN/en-us'],
'gathabbrev': 'AN',
'gathname':'ArabianNights'
},
'AQ':{'name':'Antiquities',
'dir':'AQ',
'abbrev':'AQ',
'gathdirs':['AQ/en-us'],
'gathabbrev': 'AQ',
'gathname':'Antiquities',
},
'LG':{'name':'Legends',
'dir':'LG',
'abbrev':'LG',
'gathdirs':['LG/en-us'],
'gathabbrev': 'LE',
'gathname':'Legends',
},
'DK':{'name':'The Dark',
'dir':'DK',
'abbrev':'DK',
'gathdirs':['DK/en-us'],
'gathabbrev': 'DK',
'gathname':'TheDark',
},
'FE':{'name':'Fallen Empires',
'dir':'FE',
'abbrev':'FE',
'gathdirs':['FE/en-us'],
'gathabbrev': 'FE',
'gathname':'FallenEmpires',
},
'IA':{'name':'Ice Age',
'dir':'IA',
'abbrev':'IA',
'gathdirs':['IA/en-us'],
'gathabbrev': 'IA',
'gathname':'IceAge',
},
'HL':{'name':'Homelands',
'dir':'HL',
'abbrev':'HL',
'gathdirs':['HM/en-us'],
'gathabbrev': 'HM',
'gathname':'Homelands'
},
'AL':{'name':'Alliances',
'dir':'AL',
'abbrev':'AL',
'gathdirs':['AL/en-us'],
'gathabbrev': 'AL',
'gathname':'Alliances',
},
'MI':{'name':'Mirage',
'dir':'MI',
'abbrev':'MI',
'gathdirs':['MI/en-us'],
'gathabbrev': 'MI',
'gathname':'Mirage',
},
'VI':{'name':'Visions',
'dir':'VI',
'abbrev':'VI',
'gathabbrev': 'VI',
'gathname':'Visions',
},
'WL':{'name':'Weatherlight',
'dir':'WL',
'abbrev':'WL',
'gathabbrev': 'WL',
'gathname':'Weatherlight',
},
'TE':{'name':'Tempest',
'dir':'TE',
'abbrev':'TE',
'gathabbrev': 'TE',
'gathname':'Tempest',
},
'SH':{'name':'Stronghold',
'dir':'SH',
'abbrev':'SH',
'gathabbrev': 'ST',
'gathname':'Stronghold',
},
'EX':{'name':'Exodus',
'dir':'EX',
'abbrev':'EX',
'gathabbrev': 'EX',
'gathname':'Exodus',
},
'US':{'name':'Urza\'s Saga',
'dir':'US',
'abbrev':'US',
'gathabbrev': 'UZ',
'gathname':'UrzasSaga',
},
'UL':{'name':'Urza\'s Legacy',
'dir':'UL',
'abbrev':'UL',
'gathabbrev': 'GU',
'gathname':'UrzasDestiny',
},
'UD':{'name':'Urza\'s Destiny',
'dir':'UD',
'abbrev':'UD',
'gathabbrev': 'CG',
'gathname':'UrzasLegacy',
},
'MM':{'name':'Mercadian Masques',
'dir':'MM',
'abbrev':'MM',
'gathabbrev': 'MM',
'gathname':'MercadianMasques',
},
'NE':{'name':'Nemesis',
'dir':'NE',
'abbrev':'NE',
'gathabbrev': 'NE',
'gathname':'Nemesis',
},
'PY':{'name':'Prophecy',
'dir':'PY',
'abbrev':'PY',
'gathabbrev': 'PR',
'gathname':'Prophecy',
},
'IN':{'name':'Invasion',
'dir':'IN',
'abbrev':'IN',
'gathabbrev': 'IN',
'gathname':'Invasion',
},
'PS':{'name':'Planeshift',
'dir':'PS',
'abbrev':'PS',
'gathabbrev': 'PS',
'gathname':'Planeshift',
},
'AP':{'name':'Apocalypse',
'dir':'AP',
'abbrev':'AP',
'gathabbrev': 'AP',
'gathname':'Apocalypse',
},
'OD':{'name':'Odyssey',
'dir':'OD',
'abbrev':'OD',
'gathabbrev': 'OD',
'gathname':'Odyssey',
},
'TO':{'name':'Torment',
'dir':'TO',
'abbrev':'TO',
'gathabbrev': 'TOR',
'gathname':'Torment',
},
'JD':{'name':'Judgment',
'dir':'JD',
'abbrev':'JD',
'gathabbrev': 'JUD',
'gathname':'Judgment',
},
'ON':{'name':'Onslaught',
'dir':'ON',
'abbrev':'ON',
'gathabbrev': 'ONS',
'gathname':'Onslaught',
},
'LE':{'name':'Legions',
'dir':'LE',
'abbrev':'LE',
'gathabbrev': 'LGN',
'gathname':'Legions',
},
'SC':{'name':'Scourge',
'dir':'SC',
'abbrev':'SC',
'gathabbrev': 'SCG',
'gathname':'Scourge',
},
'MR':{'name':'Mirrodin',
'dir':'MR',
'abbrev':'MR',
'gathabbrev': 'MRD',
'gathname':'Mirrodin',
},
'DS':{'name':'Darksteel',
'dir':'DS',
'abbrev':'DS',
'gathabbrev': 'DST',
'gathname':'Darksteel',
},
'FD':{'name':'Fifth Dawn',
'dir':'FD',
'abbrev':'FD',
'gathabbrev': '5DN',
'gathname':'FifthDawn',
},
'CK':{'name':'Champions of Kamigawa',
'dir':'CK',
'abbrev':'CK',
'gathabbrev': 'CHK',
'gathname':'ChampionsofKamigawa',
},
'BK':{'name':'Betrayers of Kamigawa',
'dir':'BK',
'abbrev':'BK',
'gathabbrev': 'BOK',
'gathname':'BetrayersofKamigawa',
},
'SK':{'name':'Saviors of Kamigawa',
'dir':'SK',
'abbrev':'SK',
'gathabbrev': 'SOK',
'gathname':'SaviorsofKamigawa',
},
'RA':{'name':'Ravnica: City of Guilds',
'dir':'RA',
'abbrev':'RA',
'gathabbrev': 'RAV',
'gathname':'RavnicaCityofGuilds',
},
'GP':{'name':'Guildpact',
'dir':'GP',
'abbrev':'GP',
'gathabbrev': 'GPT',
'gathname':'Guildpact',
},
'DI':{'name':'Dissension',
'dir':'DI',
'abbrev':'DI',
'gathabbrev': 'DIS',
'gathname':'Dissension',
},
'CS':{'name':'Coldsnap',
'dir':'CS',
'abbrev':'CS',
'gathabbrev':'CSP',
'gathname':'Coldsnap',
},
'TS':{'name':'Time Spiral',
'gathname':'TimeSpiralBlock',
'gathabbrev':'(?:(?:TSP)|(?:TSB))',
'dir':'TS',
'abbrev':'TS',
'gathdirs' : ('TSP','TSB'),
},
'PC':{'name':'Planar Chaos',
'gathname':'Planar%20Chaos',
'gathabbrev':'PLC',
'dir':'PC',
'abbrev':'PC',
},
'S1':{'name':'Starter 1999',
'gathname':'Starter%201999',
'gathabbrev':'P3',
'gathdirs':['P3'],
'dir':'S1',
'abbrev':'S1'
},
'S2':{'name':'Starter 2000',
'gathname':'Starter%202000',
'gathabbrev':'P4',
'dir':'S1',
'abbrev':'S1'
},
'FS':{'name':'Future Sight',
'gathname':'Future%20Sight',
'gathabbrev':'FUT',
'gathdirs':['FUT'],
'dir':'FS',
'abbrev':'FS'
},
}
def maketransU(s1, s2, todel=""):
trans_tab = dict( zip( map(ord, s1), map(ord, s2) ) )
trans_tab.update( (ord(c),None) for c in todel )
return trans_tab
imagetrans = maketransU(u'\xe2\xea\xee\xf4\xfb\xe1\xe9\xed\xf3\xfa\xfd\xe4\xeb\xef\xf6\xfc\xff\xe5\xc2\xca\xce\xd4\xdb\xc1\xc9\xcd\xd3\xda\xdd\xc4\xcb\xcf\xd6\xdc\xc5',u'aeiouaeiouyaeiouyaAEIOUAEIOUYAEIOUA',u"'/,. &;!")
imagetrans[198]=u'AE'
nametrans = maketransU(u'\xe2\xea\xee\xf4\xfb\xe1\xe9\xed\xf3\xfa\xfd\xe4\xeb\xef\xf6\xfc\xff\xe5\xc2\xca\xce\xd4\xdb\xc1\xc9\xcd\xd3\xda\xdd\xc4\xcb\xcf\xd6\xdc\xc5',u'aeiouaeiouyaeiouyaAEIOUAEIOUYAEIOUA')
nametrans[198]=u'AE'
cleanuptrans = {ord(u'\r'):u' ',
ord(u'"'):u'&quot;',
ord(u'\u2018'):ord(u'\''),
ord(u'&'):u'&amp;',
}
colorSymbols = {'red':'R',
'green' : 'G',
'blue':'U',
'black':'B',
'white':'W'}
symbolColors = dict([reversed(a) for a in colorSymbols.items()])
basic_lands = ('Mountain','Forest','Island','Swamp','Plains')
color_re = re.compile(".*(?P<color>[Rr]ed|[Gg]reen|[Bb]lue|[Bb]lack|[Ww]hite).*")
mana_re = re.compile(".*Symbol_(?P<type>.*)_mana\.gif.*")
tap_re = re.compile(".*tap.gif.*")
basicLand_re = re.compile("\[(?P<mana>.)\]")
split_re = re.compile("(?P<t1>.*) // (?P<name2>.*) (?P<mana2>\{.*\}) (?P<type2>.*) (?P<t2>.*)")
id_re = re.compile(".*id=(?P<id>\d*).*")
reminder_re = re.compile('(\A[^\(]*)|((?<=\))[^\(]*)')
_stripReminderText = True;
def replaceSymbols(soup):
for symbol in soup.findAll('img'):
m = color_re.match(str(symbol['src']))
if m:
s = colorSymbols[m.group('color').lower()]
symbol.replaceWith('{' + s + '}')
m = mana_re.match(str(symbol))
if m:
if m.group('type') == "Snow":
symbol.replaceWith('{S}')
else:
symbol.replaceWith('{' + m.group('type') + '}')
m = tap_re.match(str(symbol))
if m:
symbol.replaceWith('{T}')
return soup
def getCardTypes(soup):
types = [t.strip()
for t in soup('td')[2]('font')[0].string.split('-',1)]
if (len(types) == 2):
supertype = types[0]
subtype = types[1]
else:
supertype = types[0]
subtype = ''
# replace entities, since gccg doesn't undertand them in attributes
subtype = subtype.replace("&#226;", u"\342")
return supertype, subtype
def cleanupHTMLText(htmlText, stripReminder = _stripReminderText):
for i in htmlText.findAll('br'):
i.replaceWith(' ')
for i in htmlText.findAll('i'):
i.replaceWith(''.join(i.contents))
for i in htmlText.findAll('b'):
i.replaceWith(''.join(i.contents))
text = htmlText('font')[0].renderContents(None)
# add text for Basic Land
m = basicLand_re.match(text)
if m:
text = u"{T}: Add {" + m.group('mana') + u"} to your mana pool."
if text == u"&nbsp;":
text = u""
text = text.translate(cleanuptrans)
if stripReminder:
text = ''.join([''.join(m) for m in reminder_re.findall(text)])
return text
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag
import re
import codecs
import sys
sets ={'BE':{'name':'Beta',
'dir':'BE',
'abbrev':'BE',
'gathabbrev': '2E',
'gathname':'LimitedEditionBeta',
},
'RV':{'name':'Revised',
'dir':'RV',
'abbrev':'RV',
'gathdirs':['3E/en-us'],
'gathabbrev': '3E',
'gathname':'RevisedEdition'
},
'4E':{'name':'4th Edition',
'dir':'4E',
'abbrev':'4E',
'gathdirs':['4E/en-us'],
'gathabbrev': '4E',
'gathname':'FourthEdition',
},
'5E':{'name':'5th Edition',
'dir':'5E',
'abbrev':'5E',
'gathdirs':['5E/en-us'],
'gathabbrev': '5E',
'gathname':'FifthEdition'
},
'6E':{'name':'6th Edition',
'dir':'6E',
'abbrev':'6E',
'gathdirs':['6E/en-us'],
'gathabbrev': '6E',
'gathname':'ClassicSixthEdition',
},
'7E':{'name':'7th Edition',
'dir':'7E',
'abbrev':'7E',
'gathdirs':['7E/en-us'],
'gathabbrev': '7E',
'gathname':'SeventhEdition',
},
'8E':{'name':'8th Edition',
'dir':'8E',
'abbrev':'8E',
'gathdirs':['8ED/en-us'],
'gathabbrev': '8ED',
'gathname':'EighthEdition',
},
'9E':{'name':'9th Edition',
'dir':'9E',
'abbrev':'9E',
'gathdirs':['9ED/en-us'],
'gathabbrev': '9ED',
'gathname':'NinthEdition',
},
'10E':{'name':'10th Edition',
'dir':'10E',
'abbrev':'10E',
'gathdirs':['10E/EN'],
'gathabbrev': '10E',
'gathname':'TenthEdition',
},
'EVE':{'name':'Eventide',
'dir':'EVE',
'abbrev':'EVE',
'gathdirs':['EVE/EN'],
'gathabbrev': 'EVE',
'gathname':'Eventide',
},
'SHM':{'name':'Shadowmoor',
'dir':'SHM',
'abbrev':'SHM',
'gathdirs':['SHM/EN'],
'gathabbrev': 'SHM',
'gathname':'Shadowmoor',
},
'ALA':{'name':'Shards of Alara',
'dir':'ALA',
'abbrev':'ALA',
'gathdirs':['ALA/EN'],
'gathabbrev': 'ALA',
'gathname':'ShardsOfAlara',
},
'UH':{'name':'Unhinged',
'dir':'UH',
'abbrev':'UH',
'gathdirs':['UNH/en-us'],
'gathabbrev': 'UNH',
'gathname':'Unhinged',
},
'UG':{'name':'Unglued',
'dir':'UG',
'abbrev':'UG',
'gathdirs':['UG/en-us'],
'gathabbrev':'UG',
'gathname':'Unglued',
},
'P1':{'name':'Portal',
'dir':'P1',
'abbrev':'P1',
'gathdirs':['P1/en-us'],
'gathabbrev':'P1',
'gathname':'Portal',
},
'P2':{'name':'Portal Second Age',
'dir':'P2',
'abbrev':'P2',
'gathdirs':['P2/en-us'],
'gathabbrev':'P2',
'gathname':'PortalSecondAge',
},
'P3':{'name':'Portal Three Kingdoms',
'dir':'P3',
'abbrev':'P3',
'gathdirs':['PK/en-us'],
'gathabbrev': 'PK',
'gathname':'PortalThreeKingdoms',
},
'AN':{'name':'Arabian Nights',
'dir':'AN',
'abbrev':'AN',
'gathdirs':['AN/en-us'],
'gathabbrev': 'AN',
'gathname':'ArabianNights'
},
'AQ':{'name':'Antiquities',
'dir':'AQ',
'abbrev':'AQ',
'gathdirs':['AQ/en-us'],
'gathabbrev': 'AQ',
'gathname':'Antiquities',
},
'LG':{'name':'Legends',
'dir':'LG',
'abbrev':'LG',
'gathdirs':['LG/en-us'],
'gathabbrev': 'LE',
'gathname':'Legends',
},
'DK':{'name':'The Dark',
'dir':'DK',
'abbrev':'DK',
'gathdirs':['DK/en-us'],
'gathabbrev': 'DK',
'gathname':'TheDark',
},
'FE':{'name':'Fallen Empires',
'dir':'FE',
'abbrev':'FE',
'gathdirs':['FE/en-us'],
'gathabbrev': 'FE',
'gathname':'FallenEmpires',
},
'IA':{'name':'Ice Age',
'dir':'IA',
'abbrev':'IA',
'gathdirs':['IA/en-us'],
'gathabbrev': 'IA',
'gathname':'IceAge',
},
'HL':{'name':'Homelands',
'dir':'HL',
'abbrev':'HL',
'gathdirs':['HM/en-us'],
'gathabbrev': 'HM',
'gathname':'Homelands'
},
'AL':{'name':'Alliances',
'dir':'AL',
'abbrev':'AL',
'gathdirs':['AL/en-us'],
'gathabbrev': 'AL',
'gathname':'Alliances',
},
'MI':{'name':'Mirage',
'dir':'MI',
'abbrev':'MI',
'gathdirs':['MI/en-us'],
'gathabbrev': 'MI',
'gathname':'Mirage',
},
'VI':{'name':'Visions',
'dir':'VI',
'abbrev':'VI',
'gathabbrev': 'VI',
'gathname':'Visions',
},
'WL':{'name':'Weatherlight',
'dir':'WL',
'abbrev':'WL',
'gathabbrev': 'WL',
'gathname':'Weatherlight',
},
'TE':{'name':'Tempest',
'dir':'TE',
'abbrev':'TE',
'gathabbrev': 'TE',
'gathname':'Tempest',
},
'SH':{'name':'Stronghold',
'dir':'SH',
'abbrev':'SH',
'gathabbrev': 'ST',
'gathname':'Stronghold',
},
'EX':{'name':'Exodus',
'dir':'EX',
'abbrev':'EX',
'gathabbrev': 'EX',
'gathname':'Exodus',
},
'US':{'name':'Urza\'s Saga',
'dir':'US',
'abbrev':'US',
'gathabbrev': 'UZ',
'gathname':'UrzasSaga',
},
'UL':{'name':'Urza\'s Legacy',
'dir':'UL',
'abbrev':'UL',
'gathabbrev': 'GU',
'gathname':'UrzasDestiny',
},
'UD':{'name':'Urza\'s Destiny',
'dir':'UD',
'abbrev':'UD',
'gathabbrev': 'CG',
'gathname':'UrzasLegacy',
},
'MM':{'name':'Mercadian Masques',
'dir':'MM',
'abbrev':'MM',
'gathabbrev': 'MM',
'gathname':'MercadianMasques',
},
'NE':{'name':'Nemesis',
'dir':'NE',
'abbrev':'NE',
'gathabbrev': 'NE',
'gathname':'Nemesis',
},
'PY':{'name':'Prophecy',
'dir':'PY',
'abbrev':'PY',
'gathabbrev': 'PR',
'gathname':'Prophecy',
},
'IN':{'name':'Invasion',
'dir':'IN',
'abbrev':'IN',
'gathabbrev': 'IN',
'gathname':'Invasion',
},
'PS':{'name':'Planeshift',
'dir':'PS',
'abbrev':'PS',
'gathabbrev': 'PS',
'gathname':'Planeshift',
},
'AP':{'name':'Apocalypse',
'dir':'AP',
'abbrev':'AP',
'gathabbrev': 'AP',
'gathname':'Apocalypse',
},
'OD':{'name':'Odyssey',
'dir':'OD',
'abbrev':'OD',
'gathabbrev': 'OD',
'gathname':'Odyssey',
},
'TO':{'name':'Torment',
'dir':'TO',
'abbrev':'TO',
'gathabbrev': 'TOR',
'gathname':'Torment',
},
'JD':{'name':'Judgment',
'dir':'JD',
'abbrev':'JD',
'gathabbrev': 'JUD',
'gathname':'Judgment',
},
'ON':{'name':'Onslaught',
'dir':'ON',
'abbrev':'ON',
'gathabbrev': 'ONS',
'gathname':'Onslaught',
},
'LE':{'name':'Legions',
'dir':'LE',
'abbrev':'LE',
'gathabbrev': 'LGN',
'gathname':'Legions',
},
'SC':{'name':'Scourge',
'dir':'SC',
'abbrev':'SC',
'gathabbrev': 'SCG',
'gathname':'Scourge',
},
'MR':{'name':'Mirrodin',
'dir':'MR',
'abbrev':'MR',
'gathabbrev': 'MRD',
'gathname':'Mirrodin',
},
'DS':{'name':'Darksteel',
'dir':'DS',
'abbrev':'DS',
'gathabbrev': 'DST',
'gathname':'Darksteel',
},
'FD':{'name':'Fifth Dawn',
'dir':'FD',
'abbrev':'FD',
'gathabbrev': '5DN',
'gathname':'FifthDawn',
},
'CK':{'name':'Champions of Kamigawa',
'dir':'CK',
'abbrev':'CK',
'gathdirs':['CHK/en-us'],
'gathabbrev': 'CHK',
'gathname':'ChampionsofKamigawa',
},
'BK':{'name':'Betrayers of Kamigawa',
'dir':'BK',
'abbrev':'BK',
'gathabbrev': 'BOK',
'gathname':'BetrayersofKamigawa',
},
'SK':{'name':'Saviors of Kamigawa',
'dir':'SK',
'abbrev':'SK',
'gathabbrev': 'SOK',
'gathname':'SaviorsofKamigawa',
},
'RA':{'name':'Ravnica: City of Guilds',
'dir':'RA',
'abbrev':'RA',
'gathabbrev': 'RAV',
'gathname':'RavnicaCityofGuilds',
},
'GP':{'name':'Guildpact',
'dir':'GP',
'abbrev':'GP',
'gathabbrev': 'GPT',
'gathname':'Guildpact',
},
'DI':{'name':'Dissension',
'dir':'DI',
'abbrev':'DI',
'gathabbrev': 'DIS',
'gathname':'Dissension',
},
'CS':{'name':'Coldsnap',
'dir':'CS',
'abbrev':'CS',
'gathabbrev':'CSP',
'gathname':'Coldsnap',
},
'TS':{'name':'Time Spiral',
'gathname':'TimeSpiralBlock',
'gathabbrev':'(?:(?:TSP)|(?:TSB))',
'dir':'TS',
'abbrev':'TS',
'gathdirs' : ('TSP','TSB'),
},
'PC':{'name':'Planar Chaos',
'gathname':'Planar%20Chaos',
'gathabbrev':'PLC',
'dir':'PC',
'abbrev':'PC',
},
'S1':{'name':'Starter 1999',
'gathname':'Starter%201999',
'gathabbrev':'P3',
'gathdirs':['P3'],
'dir':'S1',
'abbrev':'S1'
},
'S2':{'name':'Starter 2000',
'gathname':'Starter%202000',
'gathabbrev':'P4',
'dir':'S1',
'abbrev':'S1'
},
'FS':{'name':'Future Sight',
'gathname':'Future%20Sight',
'gathabbrev':'FUT',
'gathdirs':['FUT'],
'dir':'FS',
'abbrev':'FS'
},
}
def maketransU(s1, s2, todel=""):
trans_tab = dict( zip( map(ord, s1), map(ord, s2) ) )
trans_tab.update( (ord(c),None) for c in todel )
return trans_tab
imagetrans = maketransU(u'\xe2\xea\xee\xf4\xfb\xe1\xe9\xed\xf3\xfa\xfd\xe4\xeb\xef\xf6\xfc\xff\xe5\xc2\xca\xce\xd4\xdb\xc1\xc9\xcd\xd3\xda\xdd\xc4\xcb\xcf\xd6\xdc\xc5',u'aeiouaeiouyaeiouyaAEIOUAEIOUYAEIOUA',u"'/,. &;!")
imagetrans[198]=u'AE'
nametrans = maketransU(u'\xe2\xea\xee\xf4\xfb\xe1\xe9\xed\xf3\xfa\xfd\xe4\xeb\xef\xf6\xfc\xff\xe5\xc2\xca\xce\xd4\xdb\xc1\xc9\xcd\xd3\xda\xdd\xc4\xcb\xcf\xd6\xdc\xc5',u'aeiouaeiouyaeiouyaAEIOUAEIOUYAEIOUA')
nametrans[198]=u'AE'
cleanuptrans = {ord(u'\r'):u' ',
ord(u'"'):u'&quot;',
ord(u'\u2018'):ord(u'\''),
ord(u'&'):u'&amp;',
}
colorSymbols = {'red':'R',
'green' : 'G',
'blue':'U',
'black':'B',
'white':'W'}
symbolColors = dict([reversed(a) for a in colorSymbols.items()])
basic_lands = ('Mountain','Forest','Island','Swamp','Plains')
color_re = re.compile(".*(?P<color>[Rr]ed|[Gg]reen|[Bb]lue|[Bb]lack|[Ww]hite).*")
mana_re = re.compile(".*Symbol_(?P<type>.*)_mana\.gif.*")
tap_re = re.compile(".*tap.gif.*")
basicLand_re = re.compile("\[(?P<mana>.)\]")
split_re = re.compile("(?P<t1>.*) // (?P<name2>.*) (?P<mana2>\{.*\}) (?P<type2>.*) (?P<t2>.*)")
id_re = re.compile(".*id=(?P<id>\d*).*")
reminder_re = re.compile('(\A[^\(]*)|((?<=\))[^\(]*)')
_stripReminderText = True;
def replaceSymbols(soup):
for symbol in soup.findAll('img'):
m = color_re.match(str(symbol['src']))
if m:
s = colorSymbols[m.group('color').lower()]
symbol.replaceWith('{' + s + '}')
m = mana_re.match(str(symbol))
if m:
if m.group('type') == "Snow":
symbol.replaceWith('{S}')
else:
symbol.replaceWith('{' + m.group('type') + '}')
m = tap_re.match(str(symbol))
if m:
symbol.replaceWith('{T}')
return soup
def getCardTypes(soup):
types = [t.strip()
for t in soup('td')[2]('font')[0].string.split('-',1)]
if (len(types) == 2):
supertype = types[0]
subtype = types[1]
else:
supertype = types[0]
subtype = ''
# replace entities, since gccg doesn't undertand them in attributes
subtype = subtype.replace("&#226;", u"\342")
return supertype, subtype
def cleanupHTMLText(htmlText, stripReminder = _stripReminderText):
for i in htmlText.findAll('br'):
i.replaceWith(' ')
for i in htmlText.findAll('i'):
i.replaceWith(''.join(i.contents))
for i in htmlText.findAll('b'):
i.replaceWith(''.join(i.contents))
text = htmlText('font')[0].renderContents(None)
# add text for Basic Land
m = basicLand_re.match(text)
if m:
text = u"{T}: Add {" + m.group('mana') + u"} to your mana pool."
if text == u"&nbsp;":
text = u""
text = text.translate(cleanuptrans)
if stripReminder:
text = ''.join([''.join(m) for m in reminder_re.findall(text)])
return text