Skip to content

Instantly share code, notes, and snippets.

@soobrosa
Created September 16, 2014 17:12
Show Gist options
  • Save soobrosa/910ffb99607402fb6bfd to your computer and use it in GitHub Desktop.
Save soobrosa/910ffb99607402fb6bfd to your computer and use it in GitHub Desktop.
CSV to Google Sheers
# Usage:
# python push_to_google_sheets.py filename.csv sheet_name
#
# In case your Google Account protected
# with Two Factor Authorization,
# you have to create an application-specific password
# and use your email to login as usual.
# https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en_GB
#
# Dependency:
# https://github.com/burnash/gspread
import sys
import gspread
def main(argv):
credentials = ['--EMAIL--', '--TOKEN--']
if len(argv) < 2:
sys.stderr.write("Usage: %s filename.csv sheet_name" % (argv[0],))
return 1
if not os.path.exists(argv[1]):
sys.stderr.write("ERROR: File %r was not found!" % (argv[1],))
return 1
gc = gspread.login(credentials)
wks = gc.open(argv[2]).sheet1
fi = open(argv[1])
row = 1
column = 1
for li in fi:
items = li.strip().split(',')
for item in items:
wks.update_cell(row, column, item)
column += 1
row += 1
column = 1
worksheet.update_cells(cell_list)
fi.close()
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment