Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.ElementTree as ET
- import urllib2, re
- levels = 'http://mspaintadventures.com/storyfiles/hs2/05260/levels/openbound/'
- resources = 'http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/'
- dialogue_files = ['firstRoomDialog.xml','secondRoomDialog.xml','thirdRoomDialog.xml','fourthRoomDialog.xml']
- asset_files = ['openbound.xml','firstRoom.xml','secondRoom.xml','thirdRoom.xml','fourthRoom.xml']
- assets = {}
- for f in asset_files:
- data = urllib2.urlopen(levels + f).read()
- tree = ET.fromstring(data)
- for asset in tree.iter('asset'):
- if asset.get('type') != 'graphic':
- continue
- assets[asset.get('name')] = resources + asset.text
- conversations = []
- styles = {}
- for f in dialogue_files:
- data = urllib2.urlopen(levels + f).read()
- tree = ET.fromstring(data)
- for talk in tree.iter('action'):
- if talk.get('command') != 'talk':
- continue
- convo = []
- for match in re.finditer('@([^:\s~]*)(?:(?:~([^\s]*))|(?::([^\s]*))? (?:([^@:]*):)?([^@]*))', talk.find('args').text):
- sprite, image, hashtags, actor, dialogue = match.groups()
- image = "%sdialogs/%s.png" % (resources, image) if image else ''
- hashtags = hashtags.replace('-',' ').replace('#',' #').strip() if hashtags else ''
- actor = actor.lower() if actor else ''
- dialogue = dialogue.strip() if dialogue else ''
- # Check for andrew
- if sprite == "!":
- sprite = ""
- elif sprite:
- styles[sprite] = True
- if not sprite and not actor:
- actor = "andrew"
- convo.append({'sprite': sprite, 'image': image, 'hashtags': hashtags, 'actor': actor, 'dialogue': "%s: %s" % (actor.upper(), dialogue)})
- conversations.append(convo)
- css = []
- template = "\t\t.%s { background-image: url('%s'); }"
- for key in styles.iterkeys():
- if key in assets:
- css.append(template % (key, assets[key]))
- css = "\n".join(css)
- text = ""
- html = """<!doctype html>
- <html><head>
- <title>Openbound Dialogue</title>
- <style>
- @font-face { font-family: Sburb; src: url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/fonts/cour.ttf'), url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/fonts/cour.woff'); }
- body { font-size: 14px; font-weight: bold; font-family: Courier New, Courier, Sburb; }
- .conversation { clear: both; border-bottom: 3px solid black; }
- .dialogue { float: left; margin: 10px; }
- .sprite { height: 325px; width: 230px; float: left; background-size: 100%% auto; background-repeat: no-repeat; }
- .words { float: left; height: 325px; width: 537px; }
- .text { height: 230px; width: 497px; padding: 20px; background: url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/interface/dialogBoxBig.png'); }
- .text span { overflow: auto; }
- .text img { margin: -25px; }
- .hashtags { position: relative; color: black; height: 29px; width: 497px; padding: 13px 20px; background: url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/interface/hashtagbar.png'); }
- .permalink { position: absolute; bottom: 10px; right: 10px; font-size: 10px; font-weight: normal; }
- .meenah { color: #77003c; } .aranea { color: #005682; } .porrim { color: #008141; } .kankri { color: #ff0000; font-size: 12px; }
- .latula { color: #008282; } .aradia { color: #a10000; } .nepeta { color: #416600; } .vriska { color: #005682; }
- .tavros { color: #a15000; } .eridan { color: #6a006a; } .feferi { color: #77003c; } .karkat { color: #626262; }
- .equius { color: #000056; } .kanaya { color: #008141; } .terezi { color: #008282; } .sollux { color: #a1a100; }
- .gamzee { color: #2b0057; } .dave { color: #e00707; } .rose { color: #b536da; }
- %s
- </style>
- </head><body>
- """ % css
- id = 1
- for convo in conversations:
- html += '\t<div class="conversation">\n'
- for c in convo:
- template = '\t\t<div id="dialogue-%d" class="dialogue %s"><div class="sprite %s"></div><div class="words"><div class="text">%s</div><div class="hashtags">%s<a class="permalink" href="#dialogue-%d">Permalink</a></div></div></div>\n'
- args = (id, c['actor'], c['sprite'], '<img src="%s" />' % c['image'] if c['image'] else '<span>%s</span>' % c['dialogue'], c['hashtags'], id)
- html += template % args
- text += "%s %s\n" % (c['image'], c['hashtags']) if c['image'] else "%s %s\n" % (c['dialogue'], c['hashtags'])
- id += 1
- html += '\t</div>\n'
- text += "\n"
- html += '</body></html>'
- with open("openbound_dialogue.html","w") as f:
- f.write(html)
- with open("openbound_dialogue.txt","w") as f:
- f.write(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement