Ejemplo n.º 1
0
def convert(fp):
    rows = csv.reader(fp)
    rows.next()  # header

    root = ET.fromstring('<entities type="federal-body"></entities>')
    root.attrib['updated'] = utc.now_isoformat()

    for row in rows:
        eid, epid, ename, abbr, hist, leader = [
            c.decode('cp1252').strip() for c in row
        ]
        entity = ET.SubElement(root, 'entity')
        entity.attrib['id'] = "{:0>4s}".format(eid)
        if epid:
            entity.attrib['parent-id'] = "{:0>4s}".format(epid) if epid else ''
        name = ET.SubElement(entity, 'name')
        name.set('role', 'official')
        name.text = ename
        if hist:
            name = ET.SubElement(entity, 'name')
            name.set('role', 'historical')
            name.text = hist
        if leader:
            name = ET.SubElement(entity, 'name')
            name.set('role', 'leadership')
            name.text = leader
        if abbr:
            name = ET.SubElement(entity, 'abbr')
            name.text = abbr

    return root
Ejemplo n.º 2
0
def convert(fp):
    rows = csv.reader(fp)
    rows.next()  # header

    root = ET.fromstring('<entities type="federal-body"></entities>')
    root.attrib['updated'] = utc.now_isoformat()

    for row in rows:
        eid, epid, ename, abbr, hist, leader = [c.decode('cp1252').strip() for c in row]
        entity = ET.SubElement(root, 'entity')
        entity.attrib['id'] = "{:0>4s}".format(eid)
        if epid:
            entity.attrib['parent-id'] = "{:0>4s}".format(epid) if epid else ''
        name = ET.SubElement(entity, 'name')
        name.set('role', 'official')
        name.text = ename
        if hist:
            name = ET.SubElement(entity, 'name')
            name.set('role', 'historical')
            name.text = hist
        if leader:
            name = ET.SubElement(entity, 'name')
            name.set('role', 'leadership')
            name.text = leader
        if abbr:
            name = ET.SubElement(entity, 'abbr')
            name.text = abbr

    return root
Ejemplo n.º 3
0
def doc2xml(billversions):
    billversionET = ET.Element("entities",
        type="billversion",
        description="Definitions of Common Versions of Bills",
        source="http://www.gpo.gov/help/about_congressional_bills.htm",
        updated=utc.now_isoformat())

    for bill in billversions:
        d = bill._asdict()
        d['chambers'] = ' '.join(sorted(d['chambers']))
        version = d['version']
        del d['version']
        bv = ET.SubElement(billversionET, 'entity', **d)
        ET.SubElement(bv, 'name', role="official").text = version

    return billversionET
Ejemplo n.º 4
0
def convert(infile, outfile):
    reader = csv.reader(infile)
    reader.next()  # discard header

    acts = ET.Element('entities', type="act", updated=utc.now_isoformat())

    for row in reader:
        row = [c.decode('CP1252').strip() for c in row]
        row = map(normalize_name, row)
        act = ET.SubElement(acts, 'entity', id=row[0])
        name = ET.SubElement(act, 'name')
        name.text = row[0]
        for extraname in row[2:]:
            if extraname:
                name = ET.SubElement(act, 'name')
                name.text = extraname

    lookup = ET.ElementTree(acts)
    lookup.write(outfile, encoding="utf-8")
Ejemplo n.º 5
0
def convert(infile, outfile):
    reader = csv.reader(infile)
    reader.next()             # discard header

    acts = ET.Element('entities',
        type="act",
        updated=utc.now_isoformat()
    )

    for row in reader:
        row = [c.decode('CP1252').strip() for c in row]
        row = map(normalize_name, row)
        act = ET.SubElement(acts, 'entity', id=row[0])
        name = ET.SubElement(act, 'name')
        name.text = row[0]
        for extraname in row[2:]:
            if extraname:
                name = ET.SubElement(act, 'name')
                name.text = extraname

    lookup = ET.ElementTree(acts)
    lookup.write(outfile, encoding="utf-8")