Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. from googleapiclient.discovery import build
  2. from httplib2 import Http
  3. from oauth2client import file, client, tools
  4. from apiclient.http import MediaFileUpload
  5. from apiclient import errors
  6.  
  7. import io
  8. from apiclient.http import MediaIoBaseDownload
  9.  
  10. folder_id = 'MyID021847773466366'
  11.  
  12. try :
  13. import argparse
  14. flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
  15. except ImportError:
  16. flags = None
  17.  
  18. SCOPES = 'https://www.googleapis.com/auth/drive.file'
  19. store = file.Storage('storage.json')
  20. creds = store.get()
  21.  
  22. if not creds or creds.invalid:
  23. print("make new storage data file ")
  24. flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
  25. flow.redirect_uri = client.OOB_CALLBACK_URN
  26. authorize_url = flow.step1_get_authorize_url()
  27. creds = tools.run_flow(flow, store, flags)
  28. if flags else tools.run(flow, store)
  29.  
  30. DRIVE = build('drive', 'v2', http=creds.authorize(Http()))
  31.  
  32. FILES = (
  33. ('CVE.xlsx'),
  34. )
  35.  
  36.  
  37. folder_id = 'ds8d7s8d78s7d8s7d8'
  38.  
  39. file_metadata = {
  40. 'name': 'CVE.xlsx',
  41. 'parents': [folder_id],
  42. 'mimeType': None
  43.  
  44. }
  45. media = MediaFileUpload('CVE.xlsx',
  46. mimetype=None,
  47. resumable=True)
  48.  
  49. file = DRIVE.files().insert(body=file_metadata , media_body=media,fields='id').execute()
  50.  
  51. CSV.xlsx -- 5MB (uploaded file)
  52. CSV.xlsx -- -- (new file)
  53.  
  54. file_id = 'd56d5d5d5d5d5d'
  55. request = DRIVE.files().get_media(fileId=file_id)
  56. fh = io.FileIO('CVE.xlsx', 'wb')
  57. downloader = MediaIoBaseDownload(fh, request)
  58. done = False
  59. while done is False:
  60. status, done = downloader.next_chunk()
  61. print "Download %d%%." % int(status.progress() * 100)
  62.  
  63. file_id = 'd56d5d5d5d5d5d'
  64.  
  65. file = DRIVE.files().get(fileId=file_id).execute()
  66. updated_file = DRIVE.files().update(
  67. fileId=file_id,
  68. body=file,
  69. media_body=media).execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement