def parse_steps_stats(self): """ :return: void Parses HTML source and finds daily distance and avg daily steps """ container = self.soup.find_all( "div", {"class": "span8 daily-summary-stats-placeholder"})[0] container = container.find_all("div", {"class": "row-fluid top-xl"})[0] container = container.find_all("div", {"class": "data-bit"}) self.distance = utils.parse_num(container[1].text.split("km")[0]) self.avg = utils.parse_num(container[2].text)
def parse_steps_count(self): """ :return: void Parses HTML source and finds goal and daily steps """ container = \ self.soup.find_all("div", {"class": "span4 text-center charts"})[0] total = container.find_all( "div", {"class": "data-bit"})[0].text # finds total steps self.total = utils.parse_num(total) goal = \ container.find_all("div", {"class": "h5"})[0].text.strip().split( " ")[ -1].strip() self.goal = utils.parse_num(goal)
def parse_activity(raw_html): """ :param raw_html: str html code Raw HTML code of row of table containing activity to parse :return: dict Dict with values of activity """ columns = raw_html.find_all("td") time_day = columns[0].text.strip() # parse time of the day try: time_day = datetime.strptime( columns[0].text.strip(), "%I:%M %p").time() # account for AM/PM except: pass try: duration = utils.parse_hh_mm_ss( columns[2].text.strip()) # in case of multiple hours except: duration = utils.parse_hh_mm_ss("00:00") link = str(columns[5].a["href"]).strip() id_ref = link.split("/")[-1] try: url = utils.GARMIN_CONNECT_URL + link except: url = None return { "time_day": time_day, "kcal": utils.parse_num(columns[1].text), "duration": duration, "distance": utils.parse_num(columns[3].text.split("km")[0]), "type": columns[4].text.strip(), "name": columns[5].text.strip(), "url": url, "gpx": GCDayActivities.GPX_DOWNLOAD_URL + id_ref }
def parse_kcal_count(self): """ :return: void Finds kcal value and stores value """ container = self.soup.find_all( "div", {"class": "span8 daily-summary-stats-placeholder"})[0] container = container.find_all("div", {"class": "row-fluid top-xl"})[0] kcal_count = container.find_all("div", {"class": "data-bit"})[0].text self.kcal_count = utils.parse_num(kcal_count)
def parse_likes(self): """ :return: void Finds likes count and stores value """ container = \ self.soup.find_all("div", {"class": "span4 page-navigation"})[0] container = \ container.find_all("span", {"class": "like js-like-count"})[0] likes = container.text.strip().split(" ")[0] self.likes = utils.parse_num(likes)
def parse(self): values = self.soup.find_all("tspan") values = [str(v.text).strip().replace("%", "") for v in values] # remove jibberish try: self.highly_active = utils.parse_num(values[0]) except: pass # None try: self.active = utils.parse_num(values[1]) except: pass # None try: self.sedentary = utils.parse_num(values[2]) except: pass # None try: self.sleeping = utils.parse_num(values[3]) except: pass # None
def fix_floats(headers, headers_to_fix, data): """ :param headers: [] of str Column names of data :param headers_to_fix: [] of str Column names of data to fix the float format :param data: [] of [] Raw data :return: [] of [] Input data but with fixed floats in columns """ d = data for i in range(len(headers)): if headers[i] in headers_to_fix: # this columns id to be converted for row in range(len(data)): # convert all rows of this column d[row][i] = utils.parse_num(data[row][i]) return d