Skip to content

Instantly share code, notes, and snippets.

@dobrokot
Created November 1, 2012 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobrokot/3994253 to your computer and use it in GitHub Desktop.
Save dobrokot/3994253 to your computer and use it in GitHub Desktop.
simpliest lj foaf parse and merging to .DOT-file
import glob
from os.path import basename, splitext
ls = [l.strip() for l in open('_winnie.txt').read().splitlines() if l.strip()]
my_f = set(l[2:] for l in ls if l[0] != '#' and l[0] == '>')
my_f.remove('_winnie')
print 'digraph {'
dirs = set()
for f in glob.glob('out/*.txt'):
x = splitext(basename(f))[0]
for l in open(f).read().splitlines():
l = l.strip()
if not l:
continue
if l[0:1] == '#':
continue
y = l[2:]
if x in my_f and y in my_f:
if x != y:
if l[0] == '>':
dirs.add((x, y))
#elif l[0] == '<':
# dirs.add((y, x))
for x, y in sorted(dirs):
print '"%s" -> "%s"' % (x, y)
print '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment