Skip to content

Instantly share code, notes, and snippets.

@osima
Created November 23, 2010 08:39
Show Gist options
  • Select an option

  • Save osima/711472 to your computer and use it in GitHub Desktop.

Select an option

Save osima/711472 to your computer and use it in GitHub Desktop.
ntwo data reader
# -*- coding: utf-8 -*-
class NN5Reader(object) :
def __init__(self,nn5data):
self.nn5data=nn5data
def __recoverLineBreak( self, str ):
r=''
chars=list(str)
have_to_skip=False
for i in range( len(chars) ) :
if have_to_skip:
have_to_skip=False
continue
j=i+1
if j<len(chars) :
if chars[i]==chr(1) and chars[j]==chr(1) :
r = r+ '\n'
have_to_skip=True
continue
r = r+ chars[i]
return r
def getText(self,aCode) :
text=None
lines=self.nn5data.split('\r\n')
for i in range( len(lines) ) :
line=lines[i]
if len(line)>1 :
if line[0]==chr(1) and line[1]==chr(1) :
code=lines[i+1]
if int(code)==aCode :
text = self.__recoverLineBreak( lines[i+2] )
break
if text==None:
return ''
return text
def getTheme(self):
theme=self.__getTheme()
if theme==None:
theme=self.getText(0)
if theme==None:
theme=''
return theme
def __getTheme(self):
theme=None
lines=self.nn5data.split('\r\n')
for i in range( len(lines) ) :
line=lines[i]
if line[0]==chr(4) and line[1]==chr(2) :
#code=lines[i+1]
#print "Code:"+code[:-2]
theme = self.__recoverLineBreak( lines[i+2] )
break
return theme
import sys
import nn5utils
nn5filename=sys.argv[1]
f=open(nn5filename,'r')
nn5data=f.read()
reader=nn5utils.NN5Reader(nn5data)
theme = reader.getTheme()
print 'theme = ' +unicode( theme , 'shift_jis' )
for code in range(42) :
text = reader.getText( code )
print str(code) + ' = ' + unicode( text , 'shift_jis' )
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment