songleash

generate chansons en laisse
git clone https://a3nm.net/git/songleash/
Log | Files | Refs

printcycle.py (1513B)


      1 #!/usr/bin/python3
      2 
      3 import sys
      4 from common import fem, vowels_script, strip_accents, semivowels, start
      5 from collections import defaultdict
      6 
      7 g = defaultdict(lambda: {})
      8 
      9 visited = set()
     10 
     11 def print_list(l):
     12     global out
     13     if not start[0]:
     14         l = l[1:] + [l[1], l[2]]
     15     for i in range(len(l)-1):
     16         #w = list(g[l[i]][l[i+1]])[0]
     17         w = g[l[i]][l[i+1]]
     18         #print(w[0])
     19         fs = w[1].split('-')
     20         # remove spaces in syll for singing
     21         for i in range(len(fs)):
     22             fs[i] = ''.join(fs[i].split(' '))
     23         end = ''.join(fs[2:])
     24         ssep = ' ' if songmode else ''
     25         spl = ssep.join(fs)
     26         if w[0]:
     27             spl2 = fs[0] + ssep + fs[1] + ssep + ''.join(fs[2:])
     28         else:
     29             spl2 = spl
     30         if not songmode:
     31             spl = w[0]
     32             spl2 = w[0]
     33         sep = '' if songmode else ','
     34         prf = '' if songmode else '-'
     35         print ("%s%s %s%s %s%s %s%s%s %s%s%s"
     36                 % (spl if songmode else spl[0].upper() + spl[1:],
     37                     sep, spl, sep, spl2, sep, prf, end, sep, prf, end, sep))
     38 
     39 fname = sys.argv[1]
     40 f = open(fname)
     41 songmode = sys.argv[2] == '1'
     42 
     43 for l in sys.stdin.readlines():
     44     l = l.strip().split('\t')
     45     if len(l) < 6:
     46         l.append('')
     47     fr = (l[0] == 'f', l[1])
     48     to = (l[2] == 'f', l[3])
     49     #g[fr][to].add((l[4], l[5]))
     50     g[fr][to] = (l[4], l[5])
     51 
     52 li = []
     53 for l in f.readlines():
     54     ff = l.strip().split(' ')
     55     li.append((ff[0] == 'f', ff[1]))
     56 
     57 f.close()
     58 print_list(li)
     59