I am amateur in python and Google API. I have to create script which uploads all CSV from folder to Google Drive as sheets. So far I have this script which uses gspread to upload one csv file to one specified Google Sheet. I have a lot of those CSV and I need to upload them as sheets to google drive. I am not able find a solution to deal with multiple CSV files.
import gspread
gc = gspread.oauth(credentials_filename='/users/krzysztofpaszta/credentials.json')
content = open('ONETTF-Projects-INFO.csv', 'r').read().encode('utf-8')
gc.import_csv('1gv-bKe-flo5FwIbt_xgCp1vNn0L0KBnpiu', content)
All of information is about uploading one csv file. Could someone give me some hint how to manage to upload folder with csv files such that all files as saved in Google Drive as sheets?
Thank you for your help.
EDIT: As @metamorporpoise suggested I have modified the script, I am very very close because I can see looking at the sheet in google drive that the script is actually uploading all of my CSV but in the same moment it is replacing imported CSV with new one. That's because those files are uploading on the same sheet.
import gspread
import os
gc = gspread.oauth(credentials_filename='/users/krzysztofpaszta/credentials.json')
os.chdir('/users/krzysztofpaszta/CSVtoGD')
files = os.listdir()
for filename in files:
if filename.split(".")[1] == "csv":
content = open(filename, 'r').read().encode('utf-8')
gc.import_csv('1gv-bKe-flo5FwIbt_xgCp1vNn0L0KBnpiuRak9a1efQ', content)
Is there a way to modify the gc.import_csv to import those files to different sheets?