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("<9xcxcxcxcxcxcxcxcxcxcxc",line) #Condense our unpacked characters into a string wf_name = string.join(data,'') #open a new CSV file for this person. #If the name is shorter than 4 characters or has whitespace, the script #will exit. This should probably be fixed. FW = open('WiiFit_'+wf_name[0:4]+'.csv', 'w') recordWriter = csv.writer(FW, delimiter=",", quotechar="'", quoting=csv.QUOTE_MINIMAL) #Weigh-in data starts 0x38a1 bytes into the record FH.seek(record_start + 0x38a1) #we'll loop through the record data until it starts coming up blank while(1): #4 byte date line = FH.read(4) data = struct.unpack(">i",line) #bit shift to get the month, day, and year. Could also get time if you wanted. year = data[0] >> 20 & 0x7ff month = data[0] >> 16 & 0xf day = data[0] >> 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[0]] + [data[1]] + [data[2]]) #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