-
-
Save loctv/afb423577304f62f66ed98c657964604 to your computer and use it in GitHub Desktop.
file upload test using pydrive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydrive.auth import GoogleAuth | |
| from pydrive.drive import GoogleDrive | |
| import time | |
| gauth = GoogleAuth() | |
| gauth.LoadCredentialsFile("mycreds.txt") | |
| if gauth.credentials is None: | |
| # Authenticate if they're not there | |
| gauth.LocalWebserverAuth() | |
| elif gauth.access_token_expired: | |
| # Refresh them if expired | |
| gauth.Refresh() | |
| else: | |
| # Initialize the saved creds | |
| gauth.Authorize() | |
| # Save the current credentials to a file | |
| gauth.SaveCredentialsFile("mycreds.txt") | |
| drive = GoogleDrive(gauth) | |
| date = int(time.strftime("%Y%m%d")) | |
| upload_file_name = "{0}_{1}.csv".format('test', date) | |
| f = drive.CreateFile({'title': upload_file_name, 'parents': [{'id': '...'}]}) | |
| f.SetContentFile(filename) | |
| f.Upload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment