Hi.

I have a small dilema. I have 1 Picassa .ini file a contacts.xml file and
a few images all in the same folder.

On the images there are certian people, picassa.ini file holds the image name and
id's of people included on that image in such format:

[img_8538.jpg]
faces=rect64(4ac022d1820c8624),d5a2d2f6f0d7ccbc
backuphash=46512
[img_8551.jpg]
faces=rect64(acb64583d1eb84cb),2623af3d8cb8e040;rect64(58bf441388df9592),d85d127e5c45cdc2
backuphash=8108

and the contacts.xml holds names belonging to those id's in such format:

<contacts>
 <contact id="709c4b6f3d8d1920" name="Nikolaj Zimic" display="Nikolaj" modified_time="2010-11-11T15:05:52+01:00" sync_enabled="1"/>
 <contact id="8f757c1b974c6687" name="Joze Rugelj" display="Joze" modified_time="2010-11-11T15:05:21+01:00" sync_enabled="1"/>
</contacts>

Now what my program needs to do is first read the .ini file and take out face ID wich are: faces=rect64(acb64583d1eb84cb), >>>>2623af3d8cb8e040<<<<; number in ><. Then it needs to compare that number to an id in contacts.xml file and see what name belongs to that id lets say its Nikolaj well its gonna rename the image file to that name to the name of the person that on the image.

Recommended Answers

All 3 Replies

i also have to do it whitout a config phrazer

Stumbled across this thread...

Configparser works fine. Below an example to extract face data from picasa and use that to draw a connection graph with graphviz:

import ConfigParser
import os
import pydot
from xml.etree import ElementTree as ET
from lxml import etree
import fnmatch

spider = {}

def comb(v):
	x=[]
	for i in range(len(v)):
		for j in range(len(v)-i-1):
			x.append([v[i],v[i+j+1]])
	return x

def ReadFaces(path):
	p=ConfigParser.RawConfigParser()
	p.read(path)
	for s in p.sections():
		if p.has_option(s,"faces"):
			f=p.get(s,"faces").split(";")
			f=[x.split(",")[1] for x in f] # remove rect64(..)
			for x in comb(f):
				x.sort()
				key = x[0]+x[1]
				if not spider.has_key(key):
					spider[key]=0
				spider[key]+=1

for root, dirs, files in os.walk("."):
	ini=fnmatch.filter(files, '*casa.ini')
	if ini:
		print root+"\\"+ini[0]
		ReadFaces(root+"\\"+ini[0])

contacts={}
tree = ET.parse("C:/Users/XXX/AppData/Local/Google/Picasa2/contacts/contacts.xml")
for x in tree.findall("contact"):
	contacts[x.get("id")]=x.get("name").encode('ascii','ignore')

g = pydot.Dot(graph_type='graph',fontname="Verdana",ratio=.3)

k = sorted(spider,key=spider.get,reverse=True)
opacitymax = max(spider.values())
edges=[]
for s in k:
	n1 = s[:16]
	n2 = s[16:]
	if contacts.has_key(n1) and contacts.has_key(n2):
		n1 = contacts[n1]
		n2 = contacts[n2]
		op = hex(150-int(100*spider[s]/opacitymax))
		node_1 =  pydot.Node(n1,fontsize=50)
		node_2 =  pydot.Node(n2,fontsize=50)
		edge=pydot.Edge(node_1,node_2,color="#0000ff"+op[-2:],weight=spider[s],style="setlinewidth(%i)" % spider[s])
		edges.append(edge)
		g.add_edge(edge)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.