Skip to content

Instantly share code, notes, and snippets.

@notionparallax
Created April 7, 2014 01:13
Show Gist options
  • Save notionparallax/10013450 to your computer and use it in GitHub Desktop.
Save notionparallax/10013450 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#from selenium.webdriver.common.by import By
import pandas as pd
bodyStats = pd.read_csv('fitbit_export_20140406.csv') #get your data csv (I cheated and deleted the top row)
print bodyStats.head() #check that it works
ff = webdriver.Firefox()
ff.implicitly_wait(90) # seconds # give it a really long potential timeout in case something strange happens
ff.get('http://www.beyondthewhiteboard.com')
assert 'beyond the whiteboard' in ff.title
login = ff.find_element_by_id('login')
login.send_keys('ben@notionparallax.co.uk')
login = ff.find_element_by_id('password')
login.send_keys('my password' + Keys.RETURN)
day = ff.find_element_by_id('km-id-wb-view-tab-day') #wait for the login to process
print day
for row in bodyStats.values:
#process the csv row
weighInDate = "-".join(list(reversed(row[0].split("-")))) #ruby would do this line so much more cleanly!
weightVal = row[1]
fatPc = row[3]
print weighInDate, weightVal, fatPc
ff.get('http://www.beyondthewhiteboard.com/members/71539/weigh_ins/new') #my member number, swap it for yours
weight = ff.find_element_by_id('weigh_in_weight')
weight.send_keys(str(weightVal))
ff.find_element_by_class_name("body-fat-trigger").click()#show the fat box, can't fill it in if it isn't visible
fat = ff.find_element_by_id('weigh_in_percent_body_fat')
fat.send_keys(str(fatPc))
script = """var wid = document.getElementById('weighed-in-date');
wid.removeAttribute('readonly');
wid.removeAttribute('value');
wid.value = "{}";
""".format(weighInDate)
print script
ff.execute_script(script)
ff.find_element_by_id("weigh_in_submit").click()
done = ff.find_element_by_id('weigh-ins-chart')#wait for the weight to finish processing
#ff.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment