Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

Changing Python code logic to avoid Quota exceeded for quota metric 'Write requests' error

I have a python code ready with me which is working correctly. It uses gspread to connect with Google Sheets. E is the input column and K is the output column My code does below things :

Step 1 : clears the cell and put white color

Step 2 : Find the content between round brackets with help of regular expression

Step 3: It appends 'A' for the first value in the cell and 'B' value for the rest of the values and puts red color

However, after a while, it throws this error : gspread.exceptions.APIError: {'code': 429, 'message': "Quota exceeded for quota metric 'Write requests' and limit 'Write requests per minute per user' of service I am aware of this error. It is because I am updating the cells too many times.

Question 1 :Is there an alternate way by which I can clear the cells at once without updating it each time.

Question 2 : Is there an alternate way by which I can store all the values of the cells at one time and then print the output all at once without updating one at a time.

val_list = sheet.col_values(5)
for j in range(1, len(val_list)):
  x = val_list[j]
  sheet.update('K' + str(j + 1), '')
  sheet.format('K' + str(j + 1), {'backgroundColor': {'red': 1.0,
             'green': 1.0, 'blue': 1.0}})

  m = re.findall(r'[(](.*?)[)]', x)
  count = len(m)
  for i in range(0, count):
    if i == 0:
        val = m[0] + 'A'
        sheet.update('K' + str(j + 1), val + ' is updated now')
        sheet.format('K'+ str(j+1), {
                            "backgroundColor": {
                             "red": 1.0,
                              "green": 0.0,
                              "blue": 0.0
                              }
                              })
    elif i > 0:
        val = val + '
' + m[i] + 'B'
        sheet.update('K' + str(j + 1), val + ' are updated now')
        sheet.format('K'+ str(j+1), {
                            "backgroundColor": {
                             "red": 1.0,
                              "green": 0.0,
                              "blue": 0.0
                              }
                              })

enter image description here

question from:https://stackoverflow.com/questions/65868613/changing-python-code-logic-to-avoid-quota-exceeded-for-quota-metric-write-reque

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...