'Can anyone please tell me how can I export csv file to google sheet spreadsheet?

I have created python program to create csv files from scraping the web. Now I want to export these csv files to google sheets or google drive so that I can create a dashboard using Javascript.

I tried using this code snippet-

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
     "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]

credentials = ServiceAccountCredentials.from_json_keyfile_name('secret.json', scope)
client = gspread.authorize(credentials)

spreadsheet = client.open('CSV')

with open('headlines.csv', 'r') as file_obj:
  content = file_obj.read()
  client.import_csv(spreadsheet.id, data=content)

It is throwing error "TypeError: init() takes 1 positional argument but 2 were given" on the "spreadsheet = client.open('CSV')" line. I have created the credentials as well as enable the Google API still facing this error. Can anyone tell how to resolve this or is there a better way to export csv files to google sheet or google drive? The csv files' data will change since it is a web scraping program but still I want to export so that I can create web dashboard

P.S.- If there is a better way to create a dashboard, please do let me know. Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source