def parseXml(node): field = Field() for child in node.childNodes: if child.tagName == Coordinates.getXmlName(): field.addBoundary(Coordinates.parseXml(child)) if child.tagName == Network.getXmlName(): field.addNetwork(Network.parseXml(child)) if child.tagName == District.getXmlName(): field.addDistrict(District.parseXml(child)) return field
def getDistrict(): req = request.Request(url=url, headers=headers) rsp = request.urlopen(req) cnt = rsp.read() soup = BeautifulSoup(cnt.decode(html_encode, errors='ignore'), "html.parser") data = soup.select('.home-rcont > ul > li > a ') # 获取数据,其中select中的参数就是前面获取的路径 # print(data) dlist = [] for ss in data: d = District() d.name = ss.string d.durl = url + ss['href'] dlist.append(d) return dlist
from HabitationBuilding import HabitationBuilding from Road import Road from imp import reload import TraductorModule reload(TraductorModule) from TraductorModule import Traductor boundaries = [Coordinates(0, 0, 0), Coordinates(100, 0, 0), Coordinates(100, 100, 0), Coordinates(0, 100, 0)] field = Field(boundaries) city = City("Paris", field) road = Road([Coordinates(50, 0, 5), Coordinates(50, 50, 5)]) field.addNetwork(road) districtBoundaries = [Coordinates(10, 10, 0), Coordinates(40, 10, 0), Coordinates(40, 90, 0), Coordinates(10, 90, 0)] district = District() district.setBoundaries(districtBoundaries) field.setDistricts([district]) habitation = HabitationBuilding(districtBoundaries, 50) function = FunctionBuilding(districtBoundaries, 20) area = Area(districtBoundaries) blocks=[] for i in range(10): block = Block() block.canBuild = True block.setPlots([habitation, function, area]) blocks.append(block) district.setblocks(blocks)