Ejemplo n.º 1
0
def writeStreetsToDB(DB):
    streets = getStreetNames.getStreetsByCity(3000)
    for (streetId,streetName) in streets:
        streetDict = dict()
        streetDict['name'] = unicode(streetName)
        streetDict['id'] = unicode(streetId)
        DB.streets.save(streetDict)
def writeDB(cursor):
    """
    Gets a cursor of a DB.
    Assumes the DB has the table that holds city, street, building num, gush, helka info

     Writes into the DB all the information off the Tax website
        of all the buildings in the country
    """
    cities = getStreetNames.getCities()
    cityCounter = 0
    for city in [c for c in cities if c[0] == '3000']:
        print "STARTING ON CITY: "+ city[1].decode('utf-8')
        streets = getStreetNames.getStreetsByCity(city[0])
        streetCounter = 0
        for street in streets:
            buildingNums = getStreetNames.getBuildingNumsByStreet(street[0])
            for num in buildingNums:
                insertTuple = (city[0],city[1].decode('utf-8'),street[0],street[1].decode('utf-8'),num.decode('utf-8'))
                cursor.execute(u'INSERT into STREET_GUSH_HELKA (CITY_ID,CITY_NAME,STREET_ID,STREET_NAME,BUILDING_NUM) VALUES (?,?,?,?,?)',insertTuple)
            streetCounter = streetCounter + 1
            if streetCounter % 50 == 0:
                print "DONE "+str(streetCounter)+" STREETS"
        print "DONE WITH CITY: " + city[1].decode('utf-8')
        cityCounter = cityCounter+1
        print "CITIES LEFT: "+str(len(cities)-cityCounter)