Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from googleapiclient.discovery import build
- from httplib2 import Http
- from oauth2client import file, client, tools
- from apiclient.http import MediaFileUpload
- from apiclient import errors
- import io
- from apiclient.http import MediaIoBaseDownload
- folder_id = 'MyID021847773466366'
- try :
- import argparse
- flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
- except ImportError:
- flags = None
- SCOPES = 'https://www.googleapis.com/auth/drive.file'
- store = file.Storage('storage.json')
- creds = store.get()
- if not creds or creds.invalid:
- print("make new storage data file ")
- flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
- flow.redirect_uri = client.OOB_CALLBACK_URN
- authorize_url = flow.step1_get_authorize_url()
- creds = tools.run_flow(flow, store, flags)
- if flags else tools.run(flow, store)
- DRIVE = build('drive', 'v2', http=creds.authorize(Http()))
- FILES = (
- ('CVE.xlsx'),
- )
- folder_id = 'ds8d7s8d78s7d8s7d8'
- file_metadata = {
- 'name': 'CVE.xlsx',
- 'parents': [folder_id],
- 'mimeType': None
- }
- media = MediaFileUpload('CVE.xlsx',
- mimetype=None,
- resumable=True)
- file = DRIVE.files().insert(body=file_metadata , media_body=media,fields='id').execute()
- CSV.xlsx -- 5MB (uploaded file)
- CSV.xlsx -- -- (new file)
- file_id = 'd56d5d5d5d5d5d'
- request = DRIVE.files().get_media(fileId=file_id)
- fh = io.FileIO('CVE.xlsx', 'wb')
- downloader = MediaIoBaseDownload(fh, request)
- done = False
- while done is False:
- status, done = downloader.next_chunk()
- print "Download %d%%." % int(status.progress() * 100)
- file_id = 'd56d5d5d5d5d5d'
- file = DRIVE.files().get(fileId=file_id).execute()
- updated_file = DRIVE.files().update(
- fileId=file_id,
- body=file,
- media_body=media).execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement