Exemplo n.º 1
0
def main():
    logging.basicConfig(level=logging.DEBUG,
                format='%(asctime)s %(levelname)s %(message)s',
                filename='debug.log',
                filemode='w')
    logging.debug('Started')
    console = logging.FileHandler('error.log')
    console.setLevel(logging.ERROR)
    logging.getLogger('').addHandler(console)

    flickr = Uploadr()
    if ( not flickr.checkToken() ):
        flickr.authenticate()

    images = flickr.grabNewImages()
    logging.debug("Uploading images: %s"  % (str(images)))

    #uploads all images that are in folders and not in history file
    uploaded_now = []
    for uploaded in flickr.upload(images):
        uploaded_now.append(uploaded)
        if len(uploaded_now) > 20:
            tags2set.createSets(uploaded_now, HISTORY_FILE)
            uploaded_now = []
    if len(uploaded_now) > 0:
        tags2set.createSets(uploaded_now, HISTORY_FILE)
Exemplo n.º 2
0
def main():
    logging.basicConfig(level=logging.DEBUG,
                format='%(asctime)s %(levelname)s %(message)s',
                filename='debug.log',
                filemode='w')
    logging.debug('Started')
    console = logging.FileHandler('error.log')
    console.setLevel(logging.ERROR)
    logging.getLogger('').addHandler(console)

    flickr = Uploadr()
    if ( not flickr.checkToken() ):
        flickr.authenticate()

    images = flickr.grabNewImages()
    logging.debug("Uploading images: %s"  % (str(images)))
    #this is just double checking if everything is on Flickr what is in the history file
    # in another words it will restore history file if deleted by comparing flickr with folders
    # this takes too frickin long
    #flickr2history.reshelf(images, IMAGE_DIR, HISTORY_FILE)

    #uploads all images that are in folders and not in history file
    uploaded_now = []
    for uploaded in flickr.upload(images):
        uploaded_now.append(uploaded)
        if len(uploaded_now) > 20:
            tags2set.createSets(uploaded_now, HISTORY_FILE)
            uploaded_now = []
    if len(uploaded_now) > 0:
        tags2set.createSets(uploaded_now, HISTORY_FILE)
Exemplo n.º 3
0
 def on_message(self, message):
     
     # create new photo set
     photoset = photo_booth.new_set()
     
     self.send({'action': 'preset'})
     
     # take each photo
     count = config.getint('photobooth', 'count')
     for i in xrange(count):
         
         # pre-photo message
         self.send({
             'action': 'prephoto',
             'index': i,
             'count': count,
         })
         
         # take photo
         photo_booth.take_photo(photoset)
         photo_path = photoset['photos'][-1]
         
         # post-photo message
         self.send({
             'action': 'postphoto',
             'index': i,
             'count': count,
             'filename': photo_path.split('/')[-1],
             'localPath': photo_path,
         })
         
     self.send({'action': 'postset'})
     
     # combine into photo strip and delete originals
     strip_path = photo_booth.printout(photoset)
     photo_booth.cleanup(photoset)
     
     # upload to Flickr if enabled
     if config.get('photobooth', 'upload') == '1':
         self.send({'action': 'processing'})
         flickr_url = flickr.upload(strip_path)
         time.sleep(2)
     else:
         flickr_url = None
     
     # return final response
     self.send({
         'action': 'strip',
         'photoId': photoset['id'],
         'localPath': strip_path,
         'flickrUrl': flickr_url or '',
         'qrCodeUrl': qrcode.image_url(flickr_url or 'http://sunlightlabs.com/photobooth/'),
     })
     
     # close websocket connection
     self.send({'action': 'close'})
Exemplo n.º 4
0
    def on_message(self, message):

        # create new photo set
        photoset = photo_booth.new_set()

        self.send({"action": "preset"})

        # take each photo
        count = config.getint("photobooth", "count")
        for i in xrange(count):

            # pre-photo message
            self.send({"action": "prephoto", "index": i, "count": count})

            # take photo
            photo_booth.take_photo(photoset)
            photo_path = photoset["photos"][-1]

            # post-photo message
            self.send(
                {
                    "action": "postphoto",
                    "index": i,
                    "count": count,
                    "filename": photo_path.split("/")[-1],
                    "localPath": photo_path,
                }
            )

        self.send({"action": "postset"})

        # combine into photo strip and delete originals
        strip_path = photo_booth.printout(photoset)
        photo_booth.cleanup(photoset)

        # upload to Flickr if enabled
        if config.get("photobooth", "upload") == "1":
            self.send({"action": "processing"})
            flickr_url = flickr.upload(strip_path)
            time.sleep(2)
        else:
            flickr_url = None

        # return final response
        self.send(
            {
                "action": "strip",
                "photoId": photoset["id"],
                "localPath": strip_path,
                "flickrUrl": flickr_url or "",
                "qrCodeUrl": qrcode.image_url(flickr_url or "http://sunlightlabs.com/photobooth/"),
            }
        )

        # close websocket connection
        self.send({"action": "close"})
Exemplo n.º 5
0
logger.info('Initializing detectors...')
with Tripwire(settletime=SETTLETIME,
              detector_delay=DETECTOR_DELAY,
              sensor_pin=SENSOR_PIN) as t:
    while True:
        if t.listen():
            images = []
            for img in range(PHOTO_BURST):
                image_name = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
                image_name = image_name + '.jpeg'
                with picamera.PiCamera() as camera:
                    if PHOTO_ROTATE:
                        camera.rotation = PHOTO_ROTATE
                    camera.resolution = (2592, 1944) # Full sensor size
                    camera.capture(image_name)
                    logger.info('Picture taken')
                images.append(image_name)
            for image_name in images:
                if DBOX:
                    dbox.upload(image_name)
                if FLICKR:
                    flickr.upload(image_name)
                if TWEET:
                    twitter_postprocess(image_name)
                    twitter.update_image(image_name)
                if DBOX or TWEET or FLICKR:
                    # The image was uploaded to external server, 
                    # and can be safely removed.
                    os.remove(image_name)
Exemplo n.º 6
0
def websocket_app(environ, start_response):

    path = environ["PATH_INFO"].rstrip('/')

    if not path:

        start_response("200 OK", [('Content-Type', 'text/html')])
        return load_template('base.html')

    elif path == '/init':

        data = {'photos': []}

        for filename in os.listdir(strips_path):
            data['photos'].append(filename)

        start_response("200 OK", [('Content-Type', 'application/json')])
        return json.dumps(data)

    elif path == '/pb':

        ws = environ["wsgi.websocket"]
        #message = ws.wait()

        # create new photo set
        photoset = photo_booth.new_set()

        send(ws, {'action': 'preset'})

        # take each photo
        count = config.getint('photobooth', 'count')
        for i in xrange(count):

            # pre-photo message
            send(ws, {
                'action': 'prephoto',
                'index': i,
                'count': count,
            })

            # take photo
            photo_booth.take_photo(photoset)
            photo_path = photoset['photos'][-1]

            # post-photo message
            send(
                ws, {
                    'action': 'postphoto',
                    'index': i,
                    'count': count,
                    'filename': photo_path.split('/')[-1],
                    'localPath': photo_path,
                })

        send(ws, {'action': 'postset'})

        # combine into photo strip and delete originals
        strip_path = photo_booth.printout(photoset)
        photo_booth.cleanup(photoset)

        # upload to Flickr if enabled
        if config.get('photobooth', 'upload') == '1':
            send(ws, {'action': 'processing'})
            flickr_url = flickr.upload(strip_path)
            time.sleep(2)
        else:
            flickr_url = None

        # return final response
        ws.send(
            json.dumps({
                'action':
                'strip',
                'photoId':
                photoset['id'],
                'localPath':
                strip_path,
                'flickrUrl':
                flickr_url or '',
                'qrCodeUrl':
                qrcode.image_url(flickr_url
                                 or 'http://sunlightlabs.com/photobooth/'),
            }))

        # close websocket connection
        ws.send(json.dumps({'action': 'close'}))

    start_response("404 NOT FOUND", [('Content-Type', 'text/plain')])
    return []
Exemplo n.º 7
0
                        format='%(asctime)s %(levelname)s %(message)s',
                        filename='debug.log',
                        filemode='w')
    logging.debug('Started')
    console = logging.FileHandler('error.log')
    console.setLevel(logging.ERROR)
    logging.getLogger('').addHandler(console)

    flickr = Uploadr()
    if (not flickr.checkToken()):
        flickr.authenticate()

    #see if we need to wipe flickr account first

    if (configdict.defaults()['remove_all_pics_first'].startswith('true')):
        deleteAll.deleteAllPics()
        os._exit(
            1
        )  ## STOP HERE after deleting all media so user has chance to turn off switch before next start

    images = flickr.grabNewImages()
    #this is just double checking if everything is on Flickr what is in the history file
    # in another words it will restore history file if deleted by comparing flickr with folders
    flickr2history.reshelf(images, IMAGE_DIR, HISTORY_FILE, NUM_THREADS)

    #uploads all images that are in folders and not in history file
    flickr.upload()  #uploads all new images to flickr

    #this will organize uploaded files into sets with the names according to tags
    tags2set.createSets(HISTORY_FILE)
Exemplo n.º 8
0
def websocket_app(environ, start_response):
    
    path = environ["PATH_INFO"].rstrip('/')
    
    if not path:
        
        start_response("200 OK", [('Content-Type', 'text/html')])
        return load_template('base.html')
    
    elif path == '/init':
        
        data = {'photos': []}
        
        for filename in os.listdir(strips_path):
            data['photos'].append(filename)
        
        start_response("200 OK", [('Content-Type', 'application/json')])
        return json.dumps(data)
    
    elif path == '/pb':
        
        ws = environ["wsgi.websocket"]
        #message = ws.wait()
        
        # create new photo set
        photoset = photo_booth.new_set()
        
        send(ws, {'action': 'preset'})
        
        # take each photo
        count = config.getint('photobooth', 'count')
        for i in xrange(count):
            
            # pre-photo message
            send(ws, {
                'action': 'prephoto',
                'index': i,
                'count': count,
            })
            
            # take photo
            photo_booth.take_photo(photoset)
            photo_path = photoset['photos'][-1]
            
            # post-photo message
            send(ws, {
                'action': 'postphoto',
                'index': i,
                'count': count,
                'filename': photo_path.split('/')[-1],
                'localPath': photo_path,
            })
            
        send(ws, {'action': 'postset'})
        
        # combine into photo strip and delete originals
        strip_path = photo_booth.printout(photoset)
        photo_booth.cleanup(photoset)
        
        # upload to Flickr if enabled
        if config.get('photobooth', 'upload') == '1':
            send(ws, {'action': 'processing'})
            flickr_url = flickr.upload(strip_path)
            time.sleep(2)
        else:
            flickr_url = None
        
        # return final response
        ws.send(json.dumps({
            'action': 'strip',
            'photoId': photoset['id'],
            'localPath': strip_path,
            'flickrUrl': flickr_url or '',
            'qrCodeUrl': qrcode.image_url(flickr_url or 'http://sunlightlabs.com/photobooth/'),
        }))
        
        # close websocket connection
        ws.send(json.dumps({'action': 'close'}))
    
    start_response("404 NOT FOUND", [('Content-Type', 'text/plain')])
    return []
Exemplo n.º 9
0
 def test_flickr_upload_and_delete_work(self):
     photo_id = flickr.upload(filename=SAMPLE_IMG)
     flickr.delete(photo_id)
Exemplo n.º 10
0
 def test_flickr_upload_and_delete_work(self):
     photo_id = flickr.upload(filename=SAMPLE_IMG)
     flickr.delete(photo_id)
Exemplo n.º 11
0
if __name__ == "__main__":
    logging.basicConfig(
        level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s", filename="debug.log", filemode="w"
    )
    logging.debug("Started")
    console = logging.FileHandler("error.log")
    console.setLevel(logging.ERROR)
    logging.getLogger("").addHandler(console)

    flickr = Uploadr()
    if not flickr.checkToken():
        flickr.authenticate()

    # see if we need to wipe flickr account first

    if configdict.defaults()["remove_all_pics_first"].startswith("true"):
        deleteAll.deleteAllPics()
        os._exit(1)  ## STOP HERE after deleting all media so user has chance to turn off switch before next start

    images = flickr.grabNewImages()
    # this is just double checking if everything is on Flickr what is in the history file
    # in another words it will restore history file if deleted by comparing flickr with folders
    flickr2history.reshelf(images, IMAGE_DIR, HISTORY_FILE, NUM_THREADS)

    # uploads all images that are in folders and not in history file
    flickr.upload()  # uploads all new images to flickr

    # this will organize uploaded files into sets with the names according to tags
    tags2set.createSets(HISTORY_FILE)