Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. import RPi.GPIO as GPIO
  3. import sys, os, glob, time
  4. from boto.s3.connection import S3Connection
  5. from boto.s3.key import Key
  6.  
  7.  
  8. pin = 7
  9. GPIO.setmode(GPIO.BCM)
  10. GPIO.setup(pin, GPIO.OUT)
  11.  
  12. AWS_ACCESS =
  13. AWS_SECRET =
  14.  
  15. conn = S3Connection(AWS_ACCESS,AWS_SECRET)
  16. bucket = conn.get_bucket('be.wapptastic')
  17. directory = '/home/pi/Programs/'
  18.  
  19. def percent_cb(complete, total):
  20. sys.stdout.write('.')
  21. sys.stdout.flush()
  22.  
  23. def getFiles(dir):
  24. return [os.path.basename(x) for x in glob.glob(str(dir) + '*.jpg')]
  25.  
  26. def setPinHigh():
  27. GPIO.output(7, GPIO.HIGH)
  28.  
  29. def setPinLow():
  30. GPIO.output(7, GPIO.LOW)
  31.  
  32. def upload_S3(dir, file):
  33. k = Key(bucket)
  34. k.key = f
  35. setPinHigh()
  36. k.set_contents_from_filename(dir + f, cb=percent_cb, num_cb=10)
  37. setPinLow()
  38.  
  39. def removeLocal(dir, file):
  40. os.remove(dir + file)
  41.  
  42.  
  43. filenames = getFiles(directory)
  44. print filenames
  45.  
  46. for f in filenames:
  47. print 'rnUploading %s to Amazon S3 bucket %s' % (f, bucket)
  48. upload_S3(directory, f)
  49. removeLocal(directory, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement