def main():
    infoboxAttributes = {}

    wb = open_workbook('infoboxes.xlsx')
    sheet = wb.sheet_by_index(0)

    for row in range(2, sheet.nrows):
    # for row in range(2, 10):
        cell = str(sheet.cell(row,0).value)
        infobox = 'Template:Infobox ' + cell.replace('-', ' ')
        print 'Getting ' + str(row) + ' of ' + str(sheet.nrows) + " : " + infobox
        infoboxAttributes[infobox] = get_meta_infobox(infobox).rendered_keys()
        # for unrend, rend in infoboxAttributes[infobox].iteritems():
        #     print 'unrend : ' + infoboxAttributes[infobox][unrend]
        #     print 'rend : ' + rend
        #     infoboxAttributes[infobox][unrend] = rend.replace(u'\xa0', u' ')
        #     infoboxAttributes[infobox][unrend] = re.sub('\\u[A-Za-z0-9]{4}', ' ', rend) # unicode codes
        #     infoboxAttributes[infobox][unrend] = re.sub('\A\s+', '', rend) # leading whitespace
        #     infoboxAttributes[infobox][unrend] = re.sub('\s+\Z', '', rend) # trailing whitespace
        #     infoboxAttributes[infobox][unrend] = re.sub('\s+', ' ', rend) # repeated whitespace
        
    print 'Done. Writing to disk...'
    with open('infoboxes.json', 'wb') as fp:
        json.dump(infoboxAttributes, fp)

    print 'DONE.'
Ejemplo n.º 2
0
    def rendered_attributes(self):
        # Populate the rendered attributes dict
        if hasattr(self, '_rendered_attributes'):
            return self._rendered_attributes

        self._rendered_attributes = dict()
        ibx = get_meta_infobox(self.template())
        self._rendered_attributes.update(ibx.rendered_attributes())

        return self._rendered_attributes
Ejemplo n.º 3
0
 def test_getting_by_title(self):
     di = get_meta_infobox('Template:Infobox musical artist')
     self.assertEqual(di.symbol, "Template:Infobox musical artist")
     self.assertEqual(di.title, "Infobox musical artist")
Ejemplo n.º 4
0
 def test_regression_officeholder(self):
     mibx = get_meta_infobox('Template:Infobox officeholder')
     self.assertEqual("Died", mibx.rendered_attributes().get("death_place"))
Ejemplo n.º 5
0
 def test_musician(self):
     di = get_meta_infobox('Template:Infobox musical artist')
     self.assertEqual(di.rendered_attributes()['origin'], "Origin")
Ejemplo n.º 6
0
 def test_newlines(self):
     ibx = get_meta_infobox('Template:Infobox weapon')
     attr = ibx.rendered_attributes()['secondary_armament']
     self.assertEqual(attr, "Secondary armament")