Example #1
0
    def callback(ch, method, properties, body):
        print " [x] Received message"

        if properties.user_id is None:
            print "Ignore anonymous message"
            print " [x] Done"
            ch.basic_ack(delivery_tag = method.delivery_tag)
            return
  
        #At this point we can check if we trust this authenticated user... 
        ident=properties.user_id
        print "Received from user: %r" % ident 

        try:
            # store image in DB

            lat,lon,imgident,comment,date=exifutils.getgeoimage(body)


            #img = pexif.JpegFile.fromString(body)

            #exif = img.get_exif()
            #if exif:
            #    primary = exif.get_primary()
            #if exif is None or primary is None:
            #    print "image has no EXIF tag, skipping"
            #    imgident=None
            #else:
            #    imgident=primary.ImageDescription

            #but we check that message content is with the same ident
            #if (imgident == ident):

            #    comment="".join(img.exif.primary.ExtendedEXIF.UserComment[8:])
            #    lat,lon=img.get_geo()

            #    primary = exif.get_primary()
            #    timetag=primary.DateTime
            #    date = datetime.strptime(timetag, '%Y:%m:%d %H:%M:%S')

            print "getted those metadata from exif:"
            print lat,lon
            print comment
            print date
            print imgident

            if (imgident == ident):
                geoimage=GeorefencedImage()
                geoimage.geom = {'type': 'Point', 'coordinates': [lon, lat]}
                geoimage.comment=comment
                geoimage.date=date

                try:
                    geoimage.ident=User.objects.get(username=ident)
                    geoimage.image.save('geoimage.jpg',ContentFile(body))
                    geoimage.save()
                except User.DoesNotExist:
                    print "user does not exist"
            else:
                print "reject:",ident

        except Exception as e:
            print e
            raise

        print " [x] Done"
        ch.basic_ack(delivery_tag = method.delivery_tag)
Example #2
0
    def callback(ch, method, properties, body):
        print " [x] Received message"

        if properties.user_id is None:
            print "Ignore anonymous message"
            print " [x] Done"
            ch.basic_ack(delivery_tag=method.delivery_tag)
            return

        #At this point we can check if we trust this authenticated user...
        ident = properties.user_id
        print "Received from user: %r" % ident

        try:
            # store image in DB

            lat, lon, imgident, comment, date = exifutils.getgeoimage(body)

            #img = pexif.JpegFile.fromString(body)

            #exif = img.get_exif()
            #if exif:
            #    primary = exif.get_primary()
            #if exif is None or primary is None:
            #    print "image has no EXIF tag, skipping"
            #    imgident=None
            #else:
            #    imgident=primary.ImageDescription

            #but we check that message content is with the same ident
            #if (imgident == ident):

            #    comment="".join(img.exif.primary.ExtendedEXIF.UserComment[8:])
            #    lat,lon=img.get_geo()

            #    primary = exif.get_primary()
            #    timetag=primary.DateTime
            #    date = datetime.strptime(timetag, '%Y:%m:%d %H:%M:%S')

            print "getted those metadata from exif:"
            print lat, lon
            print comment
            print date
            print imgident

            if (imgident == ident):
                geoimage = GeorefencedImage()
                geoimage.geom = {'type': 'Point', 'coordinates': [lon, lat]}
                geoimage.comment = comment
                geoimage.date = date

                try:
                    geoimage.ident = User.objects.get(username=ident)
                    geoimage.image.save('geoimage.jpg', ContentFile(body))
                    geoimage.save()
                except User.DoesNotExist:
                    print "user does not exist"
            else:
                print "reject:", ident

        except Exception as e:
            print e
            raise

        print " [x] Done"
        ch.basic_ack(delivery_tag=method.delivery_tag)