Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Created with Python 2.7
- # Reads in from source and creates a file at destination
- source_file = "measurements.csv"
- destination_file = "converted_measurements.csv"
- height = 1.83 # in meters
- def write_file(lines):
- with open(destination_file, "w") as output:
- for line in lines:
- output.write(line + "\n")
- def bmi_calc(weight):
- bmi = round(weight / (height * height), 2)
- return bmi
- def date_flip(run_date):
- # From 2017-04-08 00:00:00 to 08-04-2017
- a = run_date.split(" ")
- b = a[0].split("-")
- return "{0}-{1}-{2}".format(b[2], b[1], b[0])
- def filter_lines(runkeeper_data):
- array = []
- for line in runkeeper_data:
- points = line.split(",")
- # has other things as well
- if points[1] == 'weight':
- array.append(convert_line(points))
- return array
- def convert_line(runkeeper_points):
- measurement_date = date_flip(runkeeper_points[0])
- weight = float(runkeeper_points[2])
- bmi = bmi_calc(weight)
- fitbit_line = "\"{0}\",\"{1}\",\"{2}\",\"{3}\"".format(measurement_date, int(round(weight)), bmi, 0)
- return fitbit_line
- runkeeper_data = []
- with open(source_file) as f:
- for line in f:
- runkeeper_data.append(line)
- header = """Body
- Date,Weight,BMI,Fat"""
- lines = [header] + filter_lines(runkeeper_data)
- write_file(lines)
Add Comment
Please, Sign In to add comment