Skip to content

Instantly share code, notes, and snippets.

@eyaler
Last active Aug 7, 2021
Embed
What would you like to do?
gsheet_fetcher.py
# to run:
# python gsheet_fetcher.py
try:
import requests # faster - need to pip install requests
get = requests.get
req = True
except:
import urllib.request
get = urllib.request.urlopen
req = False
import time
url = 'https://docs.google.com/spreadsheets/d/1pn4kw_mqTfjv-yFvCunfTH8gicSNWP46tAvgqA19gvw'
output_file = 'output.csv'
timeout = 60
sleep = 5
url = 'https://'+'/'.join(url.split('//')[-1].split('/')[:4])+'/export?format=csv'
print(url)
while True:
try:
with get(url, timeout=timeout) as r:
content = r.content if req else r.read()
print(content)
with open(output_file, 'wb') as f:
f.write(content)
except Exception as e:
print(e)
finally:
time.sleep(sleep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment