コード例 #1
0
ファイル: util.py プロジェクト: Stubbs/SheffCCWorkForYou
def truncate_ward():
	"""Unfortunatly, you can't just truncate the tables on app engine, so this method deletes them 300
	at a time, scaling that back if it gets an error."""
	
	print "Deleting WardPostcode objects"
	fetchRows = 300
	rows = WardPostcode.all().fetch(fetchRows)
	while len(rows) > 0:
		try:
			db.delete(rows)
			print "Deleted %s WardPostcode objects" % len(rows)
		except db.Timeout:
			fetchRows = fetchRows - 50
			print "Timeout, reducing rows fetched to %s" % fetchRows
			if fetchRows <= 0:
				print "Unable to fetch rows"
				exit(0)

		rows = WardPostcode.all().fetch(fetchRows)
	
	print "Deleting Ward objects"
	fetchRows = 300
	rows = Ward.all().fetch(fetchRows)
	while len(rows) > 0:
		try:
			db.delete(rows)
			print "Deleted %s Ward objects" % len(rows)
		except db.Timeout:
			fetchRows = fetchRows - 50
			print "Timeout, reducing rows fetched to %s" % fetchRows

			if fetchRows <= 0:
				print "Unable to fetch rows"
				exit(0)
		
		rows = Ward.all().fetch(fetchRows)
コード例 #2
0
ファイル: wards.py プロジェクト: Stubbs/SheffCCWorkForYou
    def parseWards(self):
        # Find the map element with the ID "map"
        mapNode = self.dom.get_element_by_id("map")

        for action, elem in etree.iterwalk(mapNode, tag="area"):
            print "Downloading %s" % elem.get("alt")

            # Find the ward object for this ward.
            if self.wards.get(elem.get("alt")):
                ward = self.wards.get(elem.get("alt"))
            else:
                try:
                    ward = Ward.all().filter("name =", elem.get("alt")).fetch(1)[0]
                    self.wards[elem.get("alt")] = ward
                except NameError, message:
                    print "Unable to find %s ward (%s)" % (elem.get("alt"), message)
                    continue

            CouncillorInfo(elem.get("href"), ward)