Example #1
0
def results(filename):
    image = app.config['UPLOAD_FOLDER']+ "/" + filename
    h1 = pHash.avhash(image)
    os.remove(image)
    reader = csv.reader(open(CATALOG, "rb"), delimiter=";")
    body = ""
    list = []
    list_count = 0
    for author, life, title, date, hash, technique, location, url, form, type in reader:
        h2 = int(hash)
        distance = pHash.hamming(h1,h2)
        document = {'author':author,'life':life,'title':title,'date':date, 'hash':hash, \
                'technique':technique, 'location':location, 'url':url, 'form':url,\
                'type':type, 'distance':distance}
        if distance < 9:
            confidence = (100 - int(distance)*5)
            document = {'author':author,'life':life,'title':title,'date':date, 'hash':hash, \
                    'technique':technique, 'location':location, 'url':url, 'form':url,\
                    'type':type, 'confidence':confidence, 'distance':distance}
            list.append(document)
            list_count = list_count + 1
    list = sorted(list, key=lambda v: v['distance'])
    counter = 0
    if  list_count > 0:
        while (counter < 5 ) and counter != list_count:
            document = list[counter]
            body += htmlify( document)
            counter = counter + 1
        return head + body + foot
    else:
        return render_template('not_found.html')
Example #2
0
import csv
import pHash
import os

reader = csv.reader(open("test.csv", "rb"), delimiter=";")

writer = csv.writer(open("testcat.csv","wb"), delimiter=";")

fields = reader.next()

for author, life, title, date, technique, location, url, form, type, school, time in reader:
    url = url.replace(".html",".jpg")
    url = url.replace("/html","/art")
    words = url.split("/")
    image = words.pop()
    os.system("wget " + url)
    hash = pHash.avhash(image)
    hashed = str(hash)
    os.remove(image)
    writer.writerow([author, life, title, date, hash, technique, location, url, form, type])
print "Done!"