Created
March 11, 2018 07:35
-
-
Save Lee-W/7748dd12d771b0dfb26349c2dfa5805b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('secret_file') | |
parser.add_argument('url') | |
parser.add_argument('worksheet_name') | |
parser.add_argument('--output_name', default='output.csv') | |
args = parser.parse_args() | |
SCOPE = ["https://spreadsheets.google.com/feeds"] | |
EXPORT_FORMAT = 'csv' | |
credentials = ServiceAccountCredentials.from_json_keyfile_name(args.secret_file, SCOPE) | |
gc = gspread.authorize(credentials) | |
spread_sheet = gc.open_by_url(args.url) | |
work_sheet = spread_sheet.worksheet(args.worksheet_name) | |
with open(args.output_name, 'wb') as output_file: | |
output_data = work_sheet.export(foramt=EXPORT_FORMAT) | |
output_file.write(output_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment