Example #1
0
def main(basepath):
    pg_user,pg_passwd,flickrapi_key,flickrapi_secret,wteapi_key=getcredentials('/root/poab/credentials.ini')
    print 'basepath: '+basepath
    for xmlfile in os.listdir(basepath):
        if xmlfile.lower().endswith('.xml'):
            print 'xmlfile: '+xmlfile
            if parsexml(basepath,xmlfile,True) == True:
                print xmlfile+' has already been parsed'
            else:
                topic,logtext,filepath,photosetname,phototitle,num_img_xml,createdate,latitude,longitude,trk_color,xmlimglist,xmltaglist,num_img_log=parsexml(basepath,xmlfile,False)
			       # topic - topic of the log-entry
			       # logtext - content-text of the log-entry
			       # filepath - where are the files belonging to this xml-file situated 
			       # photosetname - name of the set for flickr
			       # phototitle - title of the photos for flickr
			       # xmlimglist - list of the images in the xml
			       # xmltaglist - list of the images in the xml
                imagepath_fullsize=filepath+'images/sorted/'
                imagepath_resized=filepath+'images/sorted/990/'
                try:
                    trackpath=filepath+'trackfile/'
                    for trackfile in os.listdir(trackpath):
                        print trackfile
                        if trackfile.lower().endswith('.tk1'):
                            #passes outputDir,gpx-filename and tkFileName to tk2togpx.interactive to convert the tk1 to gpx
                            if os.path.exists(trackpath+trackfile[:-3]+'gpx'): # is there already a gpx-file with this name?
                                print 'gpx-file already exists, passing'
                            else:
                                tktogpx2.interactive(trackpath,trackfile.split('.')[0]+'.gpx',trackpath+trackfile)
                        else:
    			                pass 
                except IOError:
    		           print 'No Trackfile found!'
                database=db_functions.initdatabase(pg_user,pg_passwd)
    
                infomarker_id=geo_functions.gpx2database(trackpath,wteapi_key,database,trk_color,latitude,longitude,createdate)
                #files listed in xml should be geotagged already, otherwise the hash would not match anymore, image_functions.geotag is useless therefore
                #image_functions.geotag(imagepath_fullsize,imagepath_resized,trackpath)
                hashcheck,upload2flickrpath,fullsize=image_functions.checkimghash(imagepath_fullsize,imagepath_resized,xmlimglist,num_img_xml,num_img_log)
                print 'Fullsize images found:'+str(fullsize)
                if hashcheck > 0:
                    return upload2flickrpath
                image_functions.xmlimglist2db(photosetname,xmlimglist,database)
                xmlimglist_plus_db_details=image_functions.img2flickr(upload2flickrpath,fullsize,imagepath_resized,xmlimglist,xmltaglist,photosetname,phototitle,flickrapi_key,flickrapi_secret,infomarker_id,database)
                geo_functions.add_tz_country_location(xmlimglist_plus_db_details,wteapi_key,infomarker_id,database)
                log_detail=log_functions.log2db(topic,logtext,createdate,xmlimglist_plus_db_details,num_img_xml,infomarker_id,database)
                photoset_id=image_functions.getphotosetid(photosetname,database)
                if photoset_id == 0:
                    return 'Photoset not found!!!!!'
                image_functions.logid2images(log_detail,xmlimglist,photoset_id,infomarker_id,database)
                write_svg_from_db.writesvg(database)
                fill_maxmin_latlng.getmaxminbounds(database)
                finishxml(xmlfile)
                infomarker_id=''
    return 'Everything went fine i think'
print raw

for path in os.listdir('/srv/trackdata/bydate/'):
    filetypes=('.xml')
    print path
    if path.lower().endswith(filetypes):
        pass
    else:
        datepath='/srv/trackdata/bydate/'+path+'/'
        trackpath=datepath+'trackfile/'
        print 'current directory is '+path
        for trackfile in os.listdir(trackpath):
            if trackfile.lower().endswith('.tk1'):
                #passes outputDir,gpx-filename and tkFileName to tk2togpx.interactive to convert the tk1 to gpx
                if os.path.exists(trackpath+trackfile[:-3]+'gpx'): # is there already a gpx-file with this name?
                    pass
                else:
                    tktogpx2.interactive(trackpath,trackfile.split('.')[0]+'.gpx',trackpath+trackfile)
            else:
                pass
#        os.system("/usr/bin/perl /var/www/gpsPhoto.pl --dir "+datepath+"images/sorted/ --delete-geotag")
#        os.system("/usr/bin/perl /var/www/gpsPhoto.pl --dir "+datepath+"images/sorted/ --gpsdir "+datepath+'trackfile'+" --timeoffset 0 --maxtimediff 1200")
    if raw == True:
        #upload raw(NEF)-Files too
        os.system("/usr/bin/rsync -ria --progress "+datepath+"images/ [email protected]:"+datepath+"images/")
    if fullsize == True:
        #upload fullsize too
        os.system("/usr/bin/rsync -ria --progress "+datepath+"images/sorted/ [email protected]:"+datepath+"images/sorted/")
    #upload files missing in resized-directory
    os.system("/usr/bin/rsync -ria --progress "+datepath+"images/sorted/990/ [email protected]:"+datepath+"images/sorted/990/")