Exemplo n.º 1
0
def main():
    f = open('repo.repr', 'r')
    repo = eval(f.read())
    f.close()

    # create a normalized 'city' field from the jurisdiction data
    for guid in repo: repo[guid]['city'] = juris2city(repo[guid]['jurisdiction'])

    # assign each restaurant an integer row number
    sqlid_from_rguid = dict([(i[1], i[0]) for i in enumerate(repo.keys())])

    resto_rows = []
    for (guid, resto) in repo.items():
        d = {}
        d['restaurant_id'] = sqlid_from_rguid[guid]
        d['location'] = resto['name']
        d['address'] = resto['street']
        d['city'] = resto['city'] #note that we created this above
        d['latitude'], d['longitude'] = resto['lat'], resto['long']
        d['inspected'] = d['updated'] = sqlDate(resto['update'])
        d['critical'] = 0
        d['noncritical'] = int(is_naughty(repo, guid))
        d['active'] = 1
        d['closed'] = 0
        d['closed_date'] = 'NULL'
        
        row = '(%s)' % ','.join([repr(d[col]) for col in ['restaurant_id', 'location', 'address', 'city', 'latitude', 'longitude', 'inspected', 'critical', 'noncritical', 'updated', 'active', 'closed', 'closed_date']])
        resto_rows.append(row)

    # that was fun; let's do inspection data now
    inspection_rows = []
    inspSeq = 0
    for (rguid, resto) in repo.items():
        for insp in resto['inspections']:
            for finding in insp['findings']:
                d = {}
                d['inspection_id'] = inspSeq
                inspSeq += 1
                d['restaurant_id'] = sqlid_from_rguid[rguid]
                d['severity'] = 'Non-Critical'
                d['inspection_type'] = insp['reason']
                d['category'] = finding[0]
                d['description'] = finding[1][:254].replace('\0','').replace('\r','')
                d['inspected'] = sqlDate(insp['date'])
                d['active'] = 1
                row = '(%s)' % ','.join([repr(d[col]) for col in ['inspection_id', 'restaurant_id', 'severity', 'inspection_type', 'category', 'description', 'inspected', 'active']])
                inspection_rows.append(row)

    print restaurant_preamble
    print ',\n'.join(resto_rows), ';'
    print restaurant_postscript

    print inspection_preamble
    # pretend you don't see this please
    print (',\n'.join(inspection_rows)).replace("(u'", "('").replace('(u"', '("').replace(',u"',',"').replace(",u'",",'"), ';'
    print inspection_postscript

    print update_definition
Exemplo n.º 2
0
def main():
    f = open("../repo.repr", "r")
    repo = eval(f.read())
    f.close()

    outbuf = []
    for rguid in repo:
        repo[rguid]["rguid"] = rguid
        if is_naughty(repo, rguid):
            repo[rguid]["iconset"] = 2
        else:
            repo[rguid]["iconset"] = 1
        outbuf.append(poi_template % repo[rguid])

    f = open("layar.xml", "w")
    print >> f, header
    print >> f, ("\n".join(outbuf)).replace("&", "&").replace("\0", "").encode("ascii", "xmlcharrefreplace")
    print >> f, footer
    f.close()