如何使用Google Sheets的ezsheets API冻结行



我有一个用Python编写的漂亮脚本,它输入Spotify专辑URI,然后将其和一些信息添加到跟踪我听过的专辑的Google Sheet底部。

当我运行脚本时,它似乎清除了表单顶部冻结的行。在脚本的末尾,有没有办法冻结表单的第一行?

我曾尝试在末尾使用sheet.frozenRowCount(1)来冻结第一行,但我遇到了一个错误。

这是我迄今为止的代码:

#! /usr/bin/env python3
# import os
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import ezsheets
# set varialbes
cid = '{{ my cid }}'
secret = '{{ my secret key }}'
ss = ezsheets.Spreadsheet('{{ my spreadsheet }}')
sheet = ss[0]
num_rows = sheet.rowCount
spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(
client_id=cid, client_secret=secret))
# get album and set variables
album_input_raw = input("What's the album ID? ")
genre = input("What's the genre? ").title()
country = input("What country is the artist from? ").title()
listen_again_raw = input("Will you listen again? ").upper()

if listen_again_raw == "YES" or listen_again_raw == "Y":
listen_again_answer = "YES"
love_it_raw = input("Is it a new favorite? ").upper()
if love_it_raw == "YES" or listen_again_raw == "Y":
love_it_answer = "YES"
else:
love_it_answer = ""
else:
listen_again_answer = ""
album_input = album_input_raw[-22:]
album_id = f"spotify:album:{album_input}"
album_info = spotify.album(album_id)
album_name = album_info['name']
artist = album_info['artists'][0]['name']
year_raw = album_info['release_date']
year = year_raw[0:4]
# update the spreadsheet
sheet.updateRow(num_rows + 1, [album_name, artist, 'YES',
year, genre, '', country, listen_again_answer, love_it_answer])
sheet.frozenRowCount(1)

我得到这个错误:

Traceback (most recent call last):
File "/Users/scottsmith/Code/Projects/AddAlbumApp/add_album.command", line 45, in <module>
sheet.frozenRowCount(1)
TypeError: 'int' object is not callable

据我所知,ezsheets模块没有很好的文档。但看看源代码,我们可以看到以下内容:

@frozenRowCount.setter
def frozenRowCount(self, value):

因此,在您的代码中,如果您希望第一行保持冻结状态,您可以尝试以下操作:

sheet.frozenRowCount(1)

最新更新