Advertisement
Dayni

Upload

Dec 15th, 2019
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import dropbox
  4. from dropbox.exceptions import ApiError, AuthError
  5. import time
  6. import datetime
  7. import picamera
  8. import sys, os
  9. from time import sleep
  10.  
  11. # Generate timestamp string generating name for photos
  12. def timestamp():
  13. tstring = datetime.datetime.now()
  14. print("Filename generated ...")
  15. return tstring.strftime("%Y%m%d_%H%M%S")
  16. #return tstring.strftime("image")
  17.  
  18. Date = time.asctime( time.localtime(time.time()))
  19.  
  20. class TransferData:
  21. def __init__(self, access_token):
  22. self.access_token = access_token
  23. print("Uploading....")
  24.  
  25. def upload_file(self, file1_from, file1_to):
  26. """upload a file to Dropbox using API v2
  27. """
  28. dbx = dropbox.Dropbox(self.access_token)
  29.  
  30. with open(file1_from, 'rb') as f:
  31. dbx.files_upload(f.read(), file1_to)
  32.  
  33. def main():
  34. filename = timestamp()
  35. access_token = '8fEu-ziVNSAAAAAAAAAAPtmdg3mLC630heDTTuiX4kz_0Trv7EDFXUHiGzP0c9AB'
  36. transferData = TransferData(access_token)
  37.  
  38. file1_from = '/home/pi/Downloads/imag1.jpg'
  39. file1_to = "/Test/%s"%filename + ".jpg" # The full path to upload the file to, including the file name
  40.  
  41. # API v2
  42. transferData.upload_file(file1_from, file1_to)
  43.  
  44. print("Uploading complete")
  45.  
  46. if __name__ == '__main__':
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement