def upload_top_movies(wk_top_movies: Worksheet): title = 'Topplistor' if wk_top_movies.title == title: top_movies = db.top_movies() rows: List[Row] = list() for row in top_movies: imdb_link = IMDB_LINK.format(row[0]) rows.append([to_link(imdb_link, row[1]), row[2]]) row_end, col_end = len(top_movies) + 2, ALPHABETH[len(top_movies[0]) - 1] wk_top_movies.update_values(f'A3:{col_end}{row_end}', rows) else: print(f'Wrong title on worksheet. Got {wk_top_movies.title} ,expected {title}')
def upload_movies(wk_movies: Worksheet) -> None: title = 'Filmer' if wk_movies.title == title: rows: List[Row] = [] movies: List[Movie] = db.movies() for movie in movies: rows.append(get_row_rating(movie)) row_end, col_end = len(movies) + 1, ALPHABETH[len(USERS) + 4] wk_movies.update_values(f'A2:{col_end}{row_end}', rows) latest_ratings = [ [a, humanize.naturalday(b), to_link(IMDB_LINK.format(e), c), d] for (a, b, c, d, e) in db.latest_ratings(20) ] wk_movies.update_values('M12:P31', latest_ratings) else: print(f'Wrong title on worksheet. Got {wk_movies.title} ,expected {title}')
def update_sheet_from_mfp(username: str, mfp_client: myfitnesspal.Client, wks: pygsheets.Worksheet): last_cell = _get_col(wks, 1)[-1][0] row = last_cell.row last_date = datetime.strptime(last_cell.value, DATE_FORMAT) nutr_to_column = _row_to_col_index_dict(_get_row(wks, 1)[0]) for day in _date_range(last_date + timedelta(days=1)): row += 1 nutrs: List[Any] = [None] * len(nutr_to_column) nutrs[0] = day.strftime(DATE_FORMAT) mfp_nutrs = mfp_client.get_date(day, username=username) for nutrient, amount in mfp_nutrs.totals.items(): if nutrient in nutr_to_column: nutrs[nutr_to_column[nutrient]] = amount wks.update_values((row, 1), [nutrs])