fix: Extract gid from google sheets url
This commit is contained in:
parent
c2135f2471
commit
e5e6c7c9fe
1 changed files with 9 additions and 3 deletions
|
|
@ -175,12 +175,18 @@ def getlink(doctype, name):
|
|||
return '<a href="#Form/%(doctype)s/%(name)s">%(name)s</a>' % locals()
|
||||
|
||||
def get_csv_content_from_google_sheets(url):
|
||||
# https://docs.google.com/spreadsheets/d/{sheetid}}/edit#gid={gid}
|
||||
validate_google_sheets_url(url)
|
||||
|
||||
# get gid, defaults to first sheet
|
||||
if "gid=" in url:
|
||||
gid = url.rsplit('gid=', 1)[1]
|
||||
else:
|
||||
gid = 0
|
||||
# remove /edit path
|
||||
url = url.rsplit('/edit', 1)[0]
|
||||
# add /export path, defaults to first sheet
|
||||
url = url + '/export?format=csv&gid=0'
|
||||
# add /export path,
|
||||
url = url + '/export?format=csv&gid={0}'.format(gid)
|
||||
|
||||
headers = {
|
||||
'Accept': 'text/csv'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue