Thanks to Jansen’s handy chart of which bits are where, writing the parser was pretty easy. This isn’t the most elegant code I’ve ever written, but it gets the job done:
import struct import string import csv mii = 0 #we know that each record is 0x9271 bytes long record_length = 0x9281 record_start = 0 #path to WiiFit data file infile = 'RPHealth.dat' FH = open(infile, 'rb'); ## It loops through 7 profiles, because I happen to know I have 7. ## A better approach would be to go to the end of the file, of course. while (mii < 7): #go to the start of the current record FH.seek(record_start) #read the first 30 bytes (header + name) line = FH.read(30) #for some reason names are stored as N a m e instead of Name. #Throw away the header any extranous spaces data = struct.unpack("i",line) #bit shift to get the month, day, and year. Could also get time if you wanted. year = data >> 20 & 0x7ff month = data >> 16 & 0xf day = data >> 11 & 0x1f #break the loop if the date comes back 0 if(year == 0): break #format the date into something humans like to read date = str(int(year)) + '-' + str(int(month)+1) + '-' + str(int(day)) #the next three sets of 2 byte data represent weight, BMI, and balance line = FH.read(17) data = struct.unpack(">3H",line[0:6]) recordWriter.writerow([date] + [data] + [data] + [data]) #now that we're done with the record, advance to the start of the next one record_start = record_start + record_length mii = mii+1
You can download a copy of it here.