| # Method to save image, acquired from a web camera connected to a raspberry |
| # The idea is to save images with motion sensor and take an instant photograph in a forest |
| |
| |
| def __init__(self): |
| self.gps = self.getGPS() |
| self.config = { |
| .... config firebase |
| } |
| self.firebase = self.connect() |
| self.db = self.firebase.database() |
| self.db.child("list-img") |
| self.storage = self.firebase.storage() |
| self.pi = PiCamera() |
| self.dispatcher = EventDispatcher() |
| self.directoryToSave = os.path.join(self.getSaveDir(), 'images') |
| |
| def saveImage(self): |
| gen = self.getSerialName() |
| serial_name = "%s_%s" % (gen[0], gen[1]) |
| |
| file_name = '%s_%f_%f.jpg' % (serial_name, self.gps[0], self.gps[1]) |
| path_to_firebase = 'images/%s' % file_name |
| path_to_local = os.path.join(self.directoryToSave, file_name) |
| |
| data = {"filename": path_to_firebase, |
| "date": gen[0], |
| "time": gen[2], |
| "latitude": self.gps[0], |
| "longitude": self.gps[1] |
| } |
| try: |
| self.pi.exportImage(path_to_local); |
| r = self.storage.child("images/%s.jpg" % path_to_firebase).put(path_to_local) |
| print r |
| results = self.db.child().push(data) |
| print "Console: %s to firebase" % results |
| except ValueError: |
| print "Console: Firebase offline..." |