コード例 #1
0
def add2flickrndb(imageinfo,resizepath,image,database,topic,photosetname,phototitle,xmlimglist,xmltaglist,flickrapi_key,flickrapi_secret):
    session=database.db_session()
    db_trackpoint=database.db_trackpoint
    db_imageinfo=database.db_imageinfo
    db_image2tag=database.db_image2tag
    db_phototag=database.db_phototag
    db_photosets=database.db_photosets
    db_trackpoint=database.db_trackpoint
    geoinfo=os.popen("/usr/bin/exiftool -specialinstructions "+resizepath+image+"|/usr/bin/awk {'print $5 $7'}").readlines()
    print geoinfo
    if geoinfo:
        latitude,longitude=geoinfo[0].strip('\n').split(',',1)
        query_trackpoint=session.query(db_trackpoint).filter(and_(db_trackpoint.latitude==latitude,db_trackpoint.longitude==longitude))
        trackpoint_id=query_trackpoint.first().id
    #no trackpoint was near this image, so we have no
    #respective link for the db
    else:
        trackpoint_id=None
    print 'photo linked to trackpoint id:'+str(trackpoint_id)
    q=session.query(db_imageinfo).filter(db_imageinfo.id==imageinfo.id)
    imageinfo=q.one()
    imageinfo.flickrphotoid=talk2flickr.imgupload(resizepath+image,phototitle,imageinfo.flickrdescription,'')
    print imageinfo.flickrphotoid
    try:
        #sets the geolocation of the newly uploaded picture on flickr
        talk2flickr.setlocation(imageinfo.flickrphotoid,latitude,longitude,'16')
    except UnboundLocalError:
        print 'No geolocation in photo-exim-data :-('
    imageinfo.flickrfarm,imageinfo.flickrserver,imageinfo.flickrphotoid,imageinfo.flickrsecret,originalsecret,imageinfo.originalformat,imageinfo.flickrdatetaken,flickr_tags,url,title,flickrdescription = talk2flickr.getimginfo(imageinfo.flickrphotoid)
    imageexif=talk2flickr.getexif(imageinfo.flickrphotoid,imageinfo.flickrsecret)
    imageinfo.aperture=imageexif['Aperture_clean']
    imageinfo.shutter=imageexif['Exposure_clean']
    imageinfo.focal_length=imageexif['Focal Length_clean']
    imageinfo.iso=imageexif['ISO Speed_raw']
    imageinfo.online=True
    imageinfo.imgname='/'+resizepath.split('/',2)[2]+image
    imageinfo.trackpoint_id=trackpoint_id
    session.commit()
    #add photo to existing photoset on flickr
    q_photoset=session.query(db_photosets).filter(db_photosets.id==imageinfo.photoset_id)
    photoset_detail=q_photoset.one()
    talk2flickr.photoset_addphoto(photoset_detail.flickrsetid,imageinfo.flickrphotoid)
    #update photocount
    owner,primary,count,title,description=talk2flickr.get_photosetinfo(photoset_detail.flickrsetid)
    if count != photoset_detail.flickrphotocount:
        photoset_detail.flickrphotocount=count
        session.commit()
    #add tags
    tags2flickrndb(imageinfo.id,imageinfo.flickrphotoid,xmltaglist,database)
    #update trackpoint
    q = session.query(db_trackpoint).filter(db_trackpoint.id==trackpoint_id)
    if q.count() == 1:
        trackpoint=q.one()
        lat=trackpoint.latitude
        lon=trackpoint.longitude
        country=get_country(lat,lon,database)
        location=talk2flickr.findplace(lat,lon,8)
        tz_detail=get_timezone(database,lat,lon,trackpoint.timestamp,wteapi_key)
        trackpoint.timezone_id=tz_detail.id
        trackpoint.country_id=country.iso_numcode
        trackpoint.location=location
        session.commit()
        print "Added trkpt-details for imgid:"+str(imageinfo.id)+", trkptid:"+str(trackpoint.id)+", tzabb:"+tz_detail.abbreviation+", location:"+location
    else:
        print "No trackpoint for this image - therefore no timezone, location or country-details :-("
    session.close 
コード例 #2
0
ファイル: fill_photo_exif.py プロジェクト: peletiah/poab
    config=ConfigParser.ConfigParser()
    open(credentialfile)
    config.read(credentialfile)
    pg_user=config.get("postgresql","username")
    pg_passwd=config.get("postgresql","password")
    flickrapi_key=config.get("flickrcredentials","api_key")
    flickrapi_secret=config.get("flickrcredentials","api_secret")
    wteapi_key=config.get("worldtimeengine","api_key")
    return pg_user,pg_passwd,flickrapi_key,flickrapi_secret,wteapi_key

pg_user,pg_passwd,flickrapi_key,flickrapi_secret,wteapi_key=getcredentials('credentials.ini')
database=db_functions.initdatabase(pg_user,pg_passwd)
session=database.db_session()
db_imageinfo=database.db_imageinfo
q=session.query(db_imageinfo).filter(db_imageinfo.flickrphotoid!=None)
for imageinfo in q.all():
    imageexif=talk2flickr.getexif(imageinfo.flickrphotoid,imageinfo.flickrsecret)
    imageinfo.aperture=imageexif['Aperture_clean']
    imageinfo.shutter=imageexif['Exposure_clean']
    imageinfo.focal_length=imageexif['Focal Length_clean']
    imageinfo.iso=imageexif['ISO Speed_raw']
    print imageinfo.flickrtitle
    print 'id:'+str(imageinfo.id)
    print 'aperture:'+imageinfo.aperture
    print 'shutter:'+imageinfo.shutter
    print 'focal length:'+imageinfo.focal_length
    print 'ISO Speed:'+ imageinfo.iso
    print 'http://www.flickr.com/peletiah/'+imageinfo.flickrphotoid   
    session.commit()

コード例 #3
0
ファイル: image_functions.py プロジェクト: peletiah/poab
def img2flickr(upload2flickrpath,fullsize,imagepath_resized,xmlimglist,xmltaglist,photosetname,phototitle,flickrapi_key,flickrapi_secret,infomarker_id,database):
    filetypes=('.png','.jpg','.jpeg','.gif','.tif')
    session=database.db_session()
    db_trackpoint=database.db_trackpoint
    db_imageinfo=database.db_imageinfo
    db_image2tag=database.db_image2tag
    db_phototag=database.db_phototag
    db_photosets=database.db_photosets
    xmlimglist_plus_db_details=list()
    for image in sortedlistdir(upload2flickrpath):
        for imgfromxml in xmlimglist:
            if imgfromxml.name==image:
                print 'imagename=' + image
                #check if image is already in the db and uploaded
                query_imageinfo=session.query(db_imageinfo).filter(and_(db_imageinfo.photohash==imgfromxml.hash_full,db_imageinfo.photohash_990==imgfromxml.hash_resized,db_imageinfo.online==False))
                if query_imageinfo.count()==1:
                    if image.lower().endswith(filetypes):
                        #------------ GEO ------------------
                        #get the exif-geo-info with exiftool
                        #and link image with trackpoint_id
                        geoinfo=os.popen("/usr/bin/exiftool -specialinstructions "+upload2flickrpath+image+"|/usr/bin/awk {'print $5 $7'}").readlines()
                        print geoinfo
                        if geoinfo:
                            latitude,longitude=geoinfo[0].strip('\n').split(',',1)
                            query_trackpoint=session.query(db_trackpoint).filter(and_(db_trackpoint.latitude==latitude,db_trackpoint.longitude==longitude))
                            trackpoint_id=query_trackpoint.first().id
                        #no trackpoint was near this image, so we have no
                        #exact geolocation, we'll use the infomarker-location instead
                        else:
                            print 'NO GEOINFO for this IMAGE, setting INFOMARKER as locationinfomarker_id='+str(infomarker_id)
                            trackpoint_id=infomarker_id
                            q = session.query(db_trackpoint).filter(db_trackpoint.id==infomarker_id)
                            infomarker=q.one()
                            latitude,longitude=infomarker.latitude,infomarker.longitude
	                     
    	              #-----------------------------------

                    #------------ FLICKR --------------

                    flickrphotoid=talk2flickr.imgupload(upload2flickrpath+image,phototitle,imgfromxml.description+'\n\nTravelling across the globe by bike - <a href="http://poab.org" target="_blank">poab.org</a>','')
                    print flickrphotoid
                    try:
                        #sets the geolocation of the newly uploaded picture on flickr
                        talk2flickr.setlocation(flickrphotoid,latitude,longitude,'16') 
                    except UnboundLocalError:
                        print 'No geolocation in photo-exim-data :-('
	
                    #---------------------------------
                    
                    #----------- PHOTOSET ------------
                    
                    photoset_id=photoset2flickrndb(flickrapi_key,flickrapi_secret,flickrphotoid,photosetname,database)
                    
                    #---------------------------------
                    
                    #----------- IMG2DATABASE --------	   
                    
                    #fetch image-related data from flickr, then try adding photo to imageinfo
                    farm,server,flickrphotoid,secret,originalsecret,originalformat,date_taken,flickr_tags,url,title,description = talk2flickr.getimginfo(flickrphotoid)
                    imageexif=talk2flickr.getexif(flickrphotoid,secret)
                    aperture=imageexif['Aperture_clean']
                    shutter=imageexif['Exposure_clean']
                    focal_length=imageexif['Focal Length_clean']
                    iso=imageexif['ISO Speed_raw']
                    
                    imgname='/'+imagepath_resized.split('/',2)[2]+image
                       
                    imageinfo_detail=img2database(farm,server,flickrphotoid,secret,originalformat,date_taken,title,imgfromxml.description,infomarker_id,photoset_id,trackpoint_id,database,imgfromxml.hash_full,imgfromxml.hash_resized,imgname,aperture,shutter,focal_length,iso,fullsize)
                    
                    #---------------------------------
                    
                    #----------- TAGS2FLICKRNDB ------
                    
                    tags2flickrndb(imageinfo_detail.id,flickrphotoid,xmltaglist,database)
                         
                else:
                    query_imageinfo=session.query(db_imageinfo).filter(and_(db_imageinfo.photohash==imgfromxml.hash_full,db_imageinfo.photohash_990==imgfromxml.hash_resized,db_imageinfo.online==True))
                    imageinfo_detail=query_imageinfo.one()
                #------- RETURN IMAGEINFO -------
                        
                #add imageinfo_detail to imgfromxml-class and append
                #imgfromxml-class to xmlimglist_plus_db_details
                imgfromxml.imageinfo_detail=imageinfo_detail
                xmlimglist_plus_db_details.append(imgfromxml)
    return xmlimglist_plus_db_details