Skip to topic | Skip to bottom
Home"Wealth without money..."

Main.PonokoBOMcoder1.1 - 29 Jan 2009 - 03:59 - RussNelsontopic end

Start of topic | Skip to actions
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 "http://reprap.org/bin/view/Main/$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
        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'&lt;repeat\s+count="(\d+)"&gt;', line)
    if m:
        repeat = int(m.group(1))
    m = re.search(r'&lt;/repeat&gt;', line)
    if m:
        repeat = 1
    for part in re.findall(r'&lt;part(.*?)&lt;/part&gt;', line):
        m = re.match(r'(.*?)&gt;(.*)', 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)

-- RussNelson - 29 Jan 2009
to top


You are here: Main > PonokoBOM > PonokoBOMcode

to top

Copyright © 1999-2009 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RepRap? Send feedback