]>
gitweb.pimeys.fr Git - chopes.git/blob - graphe.py
2 # -*- encoding: utf-8 -*-
12 con
= psycopg2
.connect(database
= "chopes")
13 cur
= con
.cursor(cursor_factory
=psycopg2
.extras
.DictCursor
)
17 from pygraph
.classes
.graph
import graph
18 from pygraph
.classes
.digraph
import digraph
19 from pygraph
.algorithms
.searching
import breadth_first_search
20 from pygraph
.readwrite
.dot
import write
24 con
, cur
= getcursor()
25 cur
.execute("SELECT * FROM gens;")
27 gens
= {n
: nom
.decode("utf8") for n
,nom
in l
}
28 cur
.execute("SELECT id1, id2 FROM chopes;")
29 chopes
= cur
.fetchall()
33 if __name__
== "__main__":
34 gens
, chopes
= getgraph()
36 textgraph
= u
"graph chope {\n"
37 for noeud
in gens
.values():
38 textgraph
+= u
'"%s";\n' % noeud
39 #gr.add_nodes(gens.values())
41 for chopeur
, victime
in chopes
:
42 textgraph
+= u
'"%s" -- "%s";\n' % (gens
[chopeur
], gens
[victime
])
43 #gr.add_edge((gens[chopeur], gens[victime]))
48 dot
= textgraph
.encode("utf8")
49 gvv
= gv
.readstring(dot
)
51 gv
.render(gvv
, 'png', 'chopes.png')