My current approach is using this code:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
upload_file_list = ['checkpoint-5824.zip']
exist_file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format("1PtwHBXcXdmamofSgZZNpgw7wo...")}).GetList()
for upload_file in upload_file_list:
if (not os.path.exists(upload_file)):
continue
fileName = os.path.basename(upload_file)
for file1 in exist_file_list:
if file1['title'] == fileName:
file1.Delete()
gfile = drive.CreateFile({'parents': [{'id': "1PtwHBXcXdmamofSgZZNpgw7..."}], 'title': fileName})
# Read file and set it as the content of this instance.
gfile.SetContentFile(upload_file)
gfile.Upload() # Upload the file.
combine with a settings.yaml
client_config_backend: settings
client_config:
client_id:
client_secret:
save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json
get_refresh_token: True
oauth_scope:
- https://www.googleapis.com/auth/drive.file
- https://www.googleapis.com/auth/drive.install
But I fail at identification step on browser due to cannot connect via local host.
Anyone knows a solution?