fix: Extract gid from google sheets url

This commit is contained in:
Faris Ansari 2020-06-30 12:14:48 +05:30
parent c2135f2471
commit e5e6c7c9fe

View file

@ -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'
}