PonokoBOMcode

From RepRap
Revision as of 23:59, 28 January 2009 by RussNelson (talk | contribs) (version migrated from twiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

First, look at PonokoRepRap and create a file for each linked page. Update each page out of the wiki like this: for i in Ponoko*; do wget -O $i "$i?raw=on"; done

I create a parts list per page and then an overall parts list using this shell script: #!/bin/sh for i in Ponoko* all; do echo echo echo "---+ $i" echo "<pre>" if [ $i = all ]; then {| border="1" |- cat Ponoko* || part-lister |} else part-lister <$i fi echo "</pre>" done

My part-lister program is in my ~/bin directory:

#!/usr/bin/python import sys, re # Parsing shortcuts: # o If the string doesn't start with digits, the default quantity is one. lines = sys.stdin.readlines() parts = [] repeat = 1 for line in lines: # hokey XML parsing, but if you realizing that repeating needs a line break to work # correctly, you're fine. m = re.search(r'<repeat\s+count="(\d+)">', line) if m: repeat = int(m.group(1)) m = re.search(r'</repeat>', line) if m: repeat = 1 for part in re.findall(r'<part(.*?)</part>', line): m = re.match(r'(.*?)>(.*)', part) if not m: raise "this must match" options, part = m.groups() for optionmatch in re.findall(r'(\w+)="(.*?)"', options): k, v = optionmatch if k == "p": part = v + " " + part elif k == "a": # for lack of anything better to do right now, we append it to the name. part = part + " " + v else: raise "option "+k+" is not defined" part = re.sub('^a ', '1 ', part) part = re.sub('^an ', '1 ', part) part = re.sub('^one ', '1 ', part) part = re.sub('^two ', '2 ', part) part = re.sub('^three ', '3 ', part) part = re.sub('^four ', '4 ', part) part = re.sub('^five ', '5 ', part) part = re.sub('^six ', '6 ', part) part = re.sub('^seven ', '7 ', part) part = re.sub('^eight ', '8 ', part) part = re.sub('^nine ', '9 ', part) m = re.match(r'(\d+)\s+(.+)', part) if m: countpart = (repeat * int(m.group(1)), m.group(2)) else: countpart = (repeat * 1, part) parts.append(countpart) counts = {} for quantity, name in parts: counts[name] = counts.get(name, 0) + quantity keys = counts.keys() keys.sort() for k in keys: print "%3d %s" % (counts[k], k)


-- Main.RussNelson - 29 Jan 2009