I have files located on Google Drive (link "https://drive.google.com/drive/folders/1CuiRmfX2ORIzb62EM-L1x6UCm6t2uu4M?usp=sharing"). This file will be updated every day without code, just removing it from google drive and uploading a new one. I need code to do following things.
- Log into this link or just google drive
- Download all the files from csv folder (which is inside of different folder like drive/salescontrol7/csv) to folder 'project_csv' which is for now my python directory but will be deployed to heroku.
- Save downloaded files by replacing old ones in the current directory (it means if movies_metadata exists it should replace it not save as movies_matadata(1)).
I need the simplest way, so I'm using PyDrive .
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
gauth.GetFlow()
gauth.flow.params.update({'access_type': 'offline'})
gauth.flow.params.update({'approval_prompt': 'force'})
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
gauth.Refresh()
else:
gauth.Authorize()
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))
But all I was able to do get list of folders and files on my-drive. How can access to folder salescontrol7/csv and then download everything from there replacing files in project folder if there are?
Also maybe there is a way to do this without PyDrive just using publically shared link?
Thank you in advance!