Steve
Steve

Reputation: 50

Porting data structures from Python to JS

I'm building a node application to read Blizzard's MOBA game 'Heroes of the Storm' replay files. Blizzard has provided a replay parser called heroprotocol and a gentleman later ported it a nodejs version he dubbed heroprotocoljs. However he has stopped maintaining the repository a year ago and the replay versions continue to change.

Ultimately I need a way to port the data structures from a python format like this to a javascript format like this.

I've tried pyjs, javascripthon, and transcrypt. None of them seem to produce the desired result about what I'm after. These formats are very similar and a near 1-to-1 translation should be possible even if I have to resort to using regular expressions to convert it line by line.

Upvotes: 1

Views: 92

Answers (1)

fzzylogic
fzzylogic

Reputation: 2283

Have you tried exporting those structures as json? That might be what you're looking for. You can use something like this:

import json

typeinfos = [
             ('_int',[(0,7)]),  #0
             ('_int',[(0,4)]),  #1
            # ...
            ]

with open("hero.json", "w") as f:
    f.write(json.dumps(typeinfos))    

Upvotes: 1

Related Questions