Module KhipuNumbers
[hide private]
[frames] | no frames]

Source Code for Module KhipuNumbers

 1  #!/usr/bin/python2.5 
 2  """Generates the khipu-numbers.txt/yaml files, which list the numbers 
 3  (possibly) encoded in each khipu in the database.""" 
 4   
 5  from __future__ import division, with_statement 
 6  import os, StringIO, traceback, warnings, re 
 7  import json, sys 
 8   
 9  # KhipuDB is in parent dir 
10  sys.path.append('..') 
11  import KhipuDB 
12   
13  sortedSet = False 
14  results = {} 
15   
16 -def doone(khipu):
17 if khipu.investigator_num: 18 numbers = [c.numerify() for c in khipu.sorted_cords()] 19 if sortedSet: 20 numbers = [n for n in set(numbers) if n is not None] 21 numbers.sort() 22 print khipu.investigator_num + ': ' + ' '.join(map(str,numbers)) 23 results[khipu.investigator_num] = numbers
24
25 -def main ():
26 import sys 27 db = KhipuDB.KhipuDB () 28 if sys.argv[1] == 'all': 29 for khipu in db: 30 try: 31 doone(khipu) 32 except KhipuDB.MissingPrimaryCord: 33 # skip khipu which have problems. (AS022, AS33A,UR025) 34 print '*** PROBLEM WITH ' + khipu.investigator_num + ' ***' 35 with open('khipu-numbers.yaml','w') as f: 36 f.write(json.write(results)) 37 else: 38 doone(db.khipu_with_investigator_num (sys.argv[1])) 39 db.save_cache()
40 41 if __name__ == '__main__': main () 42