Automatically exported from code.google.com/p/planningalerts
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

73 Zeilen
2.7 KiB

  1. import urllib2
  2. import urllib
  3. import urlparse
  4. import datetime, time
  5. import cgi
  6. from BeautifulSoup import BeautifulSoup
  7. from PlanningUtils import PlanningApplication, \
  8. PlanningAuthorityResults, \
  9. getPostcodeFromText
  10. date_format = "%d/%m/%Y"
  11. class HounslowParser:
  12. def __init__(self, *args):
  13. self.authority_name = "London Borough of Hounslow"
  14. self.authority_short_name = "Hounslow"
  15. self.base_url = "http://planning.hounslow.gov.uk/planningv2/planning_summary.aspx?strWeekListType=SRCH&strRecTo=%(date)s&strRecFrom=%(date)s&strWard=ALL&strAppTyp=ALL&strWardTxt=All%%20Wards&strAppTypTxt=All%%20Application%%20Types&strArea=ALL&strAreaTxt=All%%20Areas&strStreet=ALL&strStreetTxt=All%%20Streets&strPC=&strLimit=500"
  16. # Limited to 500 cases - putting 1000 causes a default value of 50 to be used. 500 should be plenty.
  17. self._results = PlanningAuthorityResults(self.authority_name, self.authority_short_name)
  18. def getResultsByDayMonthYear(self, day, month, year):
  19. search_day = datetime.date(year, month, day)
  20. # Now get the search page
  21. response = urllib2.urlopen(self.base_url %{"date": search_day.strftime(date_format)})
  22. soup = BeautifulSoup(response.read())
  23. # Results are shown in a table each. The tables don't have any nice
  24. # attributes, but they do all contain a NavString "Application",
  25. # and nothing else does...
  26. nav_strings = soup.findAll(text="Application")
  27. for nav_string in nav_strings:
  28. result_table = nav_string.findPrevious("table")
  29. application = PlanningApplication()
  30. application.date_received = search_day
  31. links = result_table.findAll("a")
  32. # We can get OSGB coordinates from the link to streetmap
  33. map_qs_dict = cgi.parse_qs(urlparse.urlsplit(links[0]['href'])[3])
  34. application.osgb_x = map_qs_dict.get("x")[0]
  35. application.osgb_y = map_qs_dict.get("y")[0]
  36. application.council_reference = links[1].string.strip()
  37. application.info_url = urlparse.urljoin(self.base_url, links[1]['href'])
  38. application.comment_url = urlparse.urljoin(self.base_url, links[2]['href'])
  39. application.address = ' '.join(links[0].previous.strip().split())
  40. application.postcode = getPostcodeFromText(application.address)
  41. application.description = links[2].previous.strip()
  42. self._results.addApplication(application)
  43. return self._results
  44. def getResults(self, day, month, year):
  45. return self.getResultsByDayMonthYear(int(day), int(month), int(year)).displayXML()
  46. if __name__ == '__main__':
  47. parser = HounslowParser()
  48. print parser.getResults(1,8,2008)