User:T. Solamarle/msg2wiki

From Touhou Wiki
Jump to navigation Jump to search
#!/usr/bin/env python
# coding=utf-8

from sys import argv

snja = ('', u'死してなお、愉しく', u'門前の妖怪、習わぬ経を読む', u'直線の楽園')
snen = ('', u'An Ever More Enjoyable Death',
        u'The Youkai Before the Gate, Reading an Unlearnable Sutra',
        u'A Straight-Line Paradise')
slja = ('', u'夜桜の冥界', u'命蓮寺参道', u'命蓮寺墓地')
slen = ('', u'Night Cherry Blossoms in the Netherworld',
        u'The Road to Myouren Temple',
        u'Myouren Temple Graveyard')
sbgmja = ('', u'死霊の夜桜', u'妖怪寺へようこそ', u'素敵な墓場で暮しましょ')
sbgmen = ('', u'Night Sakura of Dead Spirits',
          u'Welcome to the Youkai Temple',
          u'Life in a Wonderful Cemetery')
bbgmja = ('', u'ゴーストリード', u'門前の妖怪小娘', u'リジッドパラダイス')
bbgmen = ('', u'Ghost Lead', u'The Youkai Girl Before the Gate', u'Rigid Paradise')
btja = ('', u'戸惑わない亡霊', u'読経するヤマビコ', u'忠実な死体')
bten = ('', u'A Non-Perplexed Phantom',
         u'The Sutra-Reciting Echo Spirit',
         u'The Loyal Corpse')
bnja = ('', u'西行寺 幽々子', u'幽谷 響子', u'宮古 芳香')
bnen = ('', 'Yuyuko Saigyouji', 'Kyouko Kasodani', 'Yoshika Miyako')

player = ''
if 'c.txt' in argv[1]:
    player = 'Sanae'
elif 'd.txt' in argv[1]:
    player = 'Youmu'
elif 'a.txt' in argv[1]:
    player = 'Reimu'
elif 'b.txt' in argv[1]:
    player = 'Marisa'
else:
    raise RuntimeError, 'Impossible player'
who = ''
stage = int(argv[1][argv[1].find('st0') + 3])
enemy = ('', 'Yuyuko', 'Kyouko', 'Yoshika')[stage]
ename = '???'

print "==Stage %d==" % stage
print "<center>[[Image:th13Stage%dtitle.jpg|frame|right|%s]]</center>" % (stage,
                                                         snen[stage])
print '{| border="1" cellpadding="5" style="border-collapse: collapse"'
print '|- align="center" |'
print '| '
print ('! width="50%%" |{{lang|ja|%s}}' % snja[stage]).encode('utf-8')
print '! width="50%%" |%s' % snen[stage]
print '|- align="center" |'
print '| '
print ('|{{lang|ja|%s}}' % slja[stage]).encode('utf-8')
print '|%s' % slen[stage]
print '|- align="center" |'
print '| '
print '!{{lang|ja|BGM:%s}}' % sbgmja[stage]
print '!BGM: %s' % sbgmen[stage]

for line in open(argv[1], 'r'):
    if 'index' in line:
        who = ''
        if 'index 1' in line:
            print '|-'
            print '| '
            print '! colspan="2" align="center" |[[%s]] DEFEATED' % enemy
    elif 'unknown 0x07' in line:
        if who == player:
            print ' '
        else:
            print '|-'
            print '!' + player
            print '|'
        who = player
    elif 'unknown 0x08' in line:
        if who == 'enemy':
            print ' '
        else:
            print '|-'
            print '!' + ename
            print '|'
        who = 'enemy'
    elif 'unknown 0x0c' in line:
        print '|- '
        print '| '
        print '! colspan="2" align="center" | [[%s]] ENTERS' % enemy
        ename = enemy
        who = ''
    elif 'unknown 0x14' in line:
        print '|- '
        print '| '
        print '!{{lang|ja|%s<br/> %s}}' % (btja[stage], bnja[stage])
        print '!%s<br/> [[%s]]' % (bten[stage], bnen[stage])
        print '|- '
        print '! ' + enemy
        print '| '
    elif 'unknown 0x13' in line:
        print '|- align="center" |'
        print '| '
        print '!{{lang|ja|BGM: %s}}' % bbgmja[stage]
        print '!BGM: %s' % bbgmen[stage]
        print '|-'
        print '! ' + enemy
        print '| '
    elif ' text ' in line:
        text = line[line.find('text ') + 6:-2]
        if text[0] == '|':
            text = text[1:]
        print text + '<br/>'

print '|}'