Exemple #1
0
def get_withings_weight(fromdate, todate):

    # Withings API
    withings = WithingsAccount(withings_auth.username, withings_auth.password)
    user = withings.get_user_by_shortname(withings_auth.shortname)
    if not user:
            print 'could not find user: %s' % withings_auth.shortname
            return
    if not user.ispublic:
            print 'user %s has not opened withings data' % \
                withings_auth.shortname
            return
    startdate = int(time.mktime(fromdate.timetuple()))
    enddate = int(time.mktime(todate.timetuple())) + 86399
    groups = user.get_measure_groups(startdate=startdate, enddate=enddate)

    weights = []
    for group in groups:
        dt = group.get_datetime()
        weight = group.get_weight()
        fat_ratio = group.get_fat_ratio()
        # print "date: %s " % dt
        # print "weight: %f lb" % (weight * POUNDS_IN_KILOGRAMS);
        # print "fat ratio: %f " % (fat_ratio or 0);
        if weight:
                weights.append(weight * POUNDS_IN_KILOGRAMS)
    return weights
Exemple #2
0
def sync(withings_username, withings_password, withings_shortname,
         garmin_username, garmin_password,
         fromdate, todate, no_upload, verbose):

    def verbose_print(s):
        if verbose:
            if no_upload:
                sys.stderr.write(s)
            else:
                sys.stdout.write(s)

    # Withings API
    withings = WithingsAccount(withings_username, withings_password)
    user = withings.get_user_by_shortname(withings_shortname)
    if not user:
        print 'could not find user: %s' % withings_shortname
        return
    if not user.ispublic:
        print 'user %s has not opened withings data' % withings_shortname
        return
    startdate = int(time.mktime(fromdate.timetuple()))
    enddate = int(time.mktime(todate.timetuple())) + 86399
    groups = user.get_measure_groups(startdate=startdate, enddate=enddate)

    # create fit file
    verbose_print('generating fit file...\n')
    fit = FitEncoder_Weight()
    fit.write_file_info()
    fit.write_file_creator()

    for group in groups:
        # get extra physical measurements

        from measurements import Measurements 
        measurements = Measurements()
    
        dt = group.get_datetime()
        weight = group.get_weight()
        fat_ratio = group.get_fat_ratio()
        fit.write_device_info(timestamp=dt)
        fit.write_weight_scale(timestamp=dt, 
            weight=weight, 
            percent_fat=fat_ratio, 
            percent_hydration=measurements.getPercentHydration()
            )
        verbose_print('appending weight scale record... %s %skg %s%%\n' % (dt, weight, fat_ratio))
    fit.finish()

    if no_upload:
        sys.stdout.write(fit.getvalue())
        return

    # garmin connect
    garmin = GarminConnect()
    cookie = garmin.login(garmin_username, garmin_password)
    verbose_print('attempting to upload fit file...\n')
    r = garmin.upload_file(fit.getvalue(), cookie)
    if r:
        verbose_print('weight.fit has been successfully uploaded!\n')
Exemple #3
0
def generate(request):
    username = request.form.get('username')
    password = request.form.get('password')
    shortname = request.form.get('shortname').upper()

    try:
        withings = WithingsAccount(username, password)
        user = withings.get_user_by_shortname(shortname)
    except WithingsAPIError, e:
        if e.status == 264:
            raise GenerateError('invalid username or password')
        raise
Exemple #4
0
def sync(withings_username, withings_password, withings_shortname,
         garmin_username, garmin_password,
         fromdate, todate, no_upload, verbose):

    def verbose_print(s):
        if verbose:
            if no_upload:
                sys.stderr.write(s)
            else:
                sys.stdout.write(s)

    # Withings API
    withings = WithingsAccount(withings_username, withings_password)
    user = withings.get_user_by_shortname(withings_shortname)
    if not user:
        print 'could not find user: %s' % withings_shortname
        return
    if not user.ispublic:
        print 'user %s has not opened withings data' % withings_shortname
        return
    startdate = int(time.mktime(fromdate.timetuple()))
    enddate = int(time.mktime(todate.timetuple())) + 86399
    groups = user.get_measure_groups(startdate=startdate, enddate=enddate)

    # create fit file
    verbose_print('generating fit file...\n')
    fit = FitEncoder_Weight()
    fit.write_file_info()
    fit.write_file_creator()

    for group in groups:
        dt = group.get_datetime()
        weight = group.get_weight()
        fat_ratio = group.get_fat_ratio()
        fit.write_device_info(timestamp=dt)
        fit.write_weight_scale(timestamp=dt, weight=weight, percent_fat=fat_ratio)
        verbose_print('appending weight scale record... %s %skg %s%%\n' % (dt, weight, fat_ratio))
    fit.finish()

    if no_upload:
        sys.stdout.write(fit.getvalue())
        return

    # garmin connect
    garmin = GarminConnect()
    garmin.login(garmin_username, garmin_password)
    verbose_print('attempting to upload fit file...\n')
    r = garmin.upload_file(fit.getvalue())
    if r:
        verbose_print('weight.fit has been successfully uploaded!\n')
Exemple #5
0
def sync(withings_username, withings_password, withings_shortname,
         garmin_username, garmin_password,
         fromdate, todate, no_upload, verbose):

    def verbose_print(s):
        if verbose:
            if no_upload:
                sys.stderr.write(s)
            else:
                sys.stdout.write(s)

    # Withings API
    withings = WithingsAccount(withings_username, withings_password)
    user = withings.get_user_by_shortname(withings_shortname)
	
    if not user:
        print 'could not find user: %s' % withings_shortname
        return
    #if not user.ispublic:
    #    print 'user %s has not opened withings data' % withings_shortname
    #    return
    startdate = int(time.mktime(fromdate.timetuple()))
    enddate = int(time.mktime(todate.timetuple())) + 86399
    groups = user.get_measure_groups(startdate=startdate, enddate=enddate)

    # create fit file
    verbose_print('generating fit file...\n')
    fit = FitEncoder_Weight()
    fit.write_file_info()
    fit.write_file_creator()

    for group in groups:
        # get extra physical measurements

        from measurements import Measurements 
        measurements = Measurements()
    
        dt = group.get_datetime()
        weight = group.get_weight()
        fat_ratio = group.get_fat_ratio()
        muscle_mass = group.get_muscle_mass()
        bone_mass=group.get_bone_mass()
        hydro = group.get_hydro()
        # mass_hydro to percent_hydro conversion
        ratio = 100 / weight
        hydro = hydro * ratio
        bone_mass = group.get_bone_mass()
        fit.write_device_info(timestamp=dt)
        fit.write_weight_scale(timestamp=dt, 
            weight=weight, 
            percent_fat=fat_ratio, 
            percent_hydration=hydro,
            muscle_mass=muscle_mass,
			bone_mass=bone_mass,
            )
        verbose_print('appending weight scale record... %s %skg %s%%\n' % (dt, weight, fat_ratio))
    fit.finish()

    if no_upload:
        sys.stdout.write(fit.getvalue())
        return

	verbose_print("Fit file: " + fit.getvalue())

    # garmin connect
    garmin = GarminConnect()
    session = garmin.login(garmin_username, garmin_password)
    verbose_print('attempting to upload fit file...\n')
    r = garmin.upload_file(fit.getvalue(), session)
    if r:
        verbose_print('weight.fit has been successfully uploaded!\n')