1

May I know what function I need to add/replace on my python script, here's my issue I have exported xlsx file from gsheet API to my server and I need to add an generic filename with file name and date (ex. FILENAME20211107.xlsx)

here's my code:

  with open("/xlsx/FILENAME.xlsx", 'wb') as f:
    f.write(res.content)
rodskies
  • 119
  • 1
  • 11
  • In your situation, from [your previous question](https://stackoverflow.com/q/69776494), you want to give the same filename of the file on Google Drive by changing the file extension. Is my understanding correct? – Tanaike Nov 08 '21 at 06:35
  • No, the goal is to set File naming convention using date in the script for example. If I run the script the extracted file from google api will be automatically named like this format "filename_202111107.xlsx" – rodskies Nov 08 '21 at 06:57
  • Thank you for replying. From your replying, I proposed an answer. Could you please confirm it? If that was not the direct solution of your issue, I apologize. – Tanaike Nov 08 '21 at 07:59

1 Answers1

0

From the goal is to set File naming convention using date in the script for example. If I run the script the extracted file from google api will be automatically named like this format "filename_202111107.xlsx", you want to use the specific filename like filename_202111107.xlsx in your script. In this case, how about the following modification?

Modified script:

import datetime # Please add this.
import os # Please add this.

path = "/xlsx/"
prefix = "sampelName"
suffix = datetime.datetime.now().strftime("%Y%m%d")
filename = prefix + "_" + suffix + ".xlsx"
v = os.path.join(path, filename)
print(v) # <--- /xlsx/sampelName_20211108.xlsx

with open(v, 'wb') as f:
  f.write(res.content)

When above script is run, v is /xlsx/sampelName_20211108.xlsx.

Note:

  • In your comment, you use 202111107 of filename_202111107.xlsx. In this case, when the script is run on November 7, 2021, you want to use 20211107. I understood like this. In your question, I understood that you might want to use 20211107 instead of 202111107.
Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Apologize for the late reply, the script is working if the file is not too big, but when I tried to larger gsheet I got an error it says that its to large to be exported... :( I hope you can help me. { "error": { "errors": [ { "domain": "global", "reason": "exportSizeLimitExceeded", "message": "This file is too large to be exported." } ], "code": 403, "message": "This file is too large to be exported." } } – rodskies Nov 18 '21 at 01:20
  • @rodskies Thank you for replying. I thought that your situation might be the same with [this issue](https://issuetracker.google.com/issues/36761333). I apologize for this. In that case, is this my answer useful? https://stackoverflow.com/a/66344211/7108653 – Tanaike Nov 18 '21 at 01:22
  • 1
    yes the date is working thank you! maybe I should file new ticket for another issue, by the way apologize again for the late reply I'm on vacation these past weeks. Thank you again @Tanaike – rodskies Nov 18 '21 at 01:38
  • @rodskies Thank you for replying. It's no problem. Thank you, too. – Tanaike Nov 18 '21 at 01:38
  • I hope you can help me again for another issue, here's the link, https://stackoverflow.com/questions/70013643/python-gsheet-export-limitation-error-exportsizelimitexceeded – rodskies Nov 18 '21 at 01:56
  • @rodskies I will check it. – Tanaike Nov 18 '21 at 01:57