Automatically exported from code.google.com/p/planningalerts
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

71 líneas
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/%b/%Y"
  11. class KingstonParser:
  12. comments_email_address = "dc@rbk.kingston.gov.uk"
  13. def __init__(self, *args):
  14. self.authority_name = "Royal Borough of Kingston upon Thames"
  15. self.authority_short_name = "Kingston upon Thames"
  16. self.base_url = "http://maps.kingston.gov.uk/isis_main/planning/planning_summary.aspx?strWeekListType=SRCH&strRecTo=%(date)s&strRecFrom=%(date)s&strWard=ALL&strAppTyp=ALL&strWardTxt=All%%20Wards&strAppTypTxt=All%%20Application%%20Types&strStreets=ALL&strStreetsTxt=All%%20Streets&strLimit=500"
  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. # Each app is stored in a table on it's own.
  24. # These tables don't have any nice distinguishing features,
  25. # but they do all contain a NavigableString "Application",
  26. # and nothing else in the page does.
  27. nav_strings = soup.findAll(text="Application")
  28. for nav_string in nav_strings:
  29. results_table = nav_string.findPrevious("table")
  30. application = PlanningApplication()
  31. application.date_received = search_day
  32. application.council_reference = results_table.a.string.strip()
  33. application.info_url = urlparse.urljoin(self.base_url, results_table.a['href'])
  34. application.address = results_table.findAll("td")[7].a.string.strip()
  35. application.postcode = getPostcodeFromText(application.address)
  36. application.description = results_table.findAll("td")[-1].contents[0].strip()
  37. # A few applications have comment urls, but most don't.
  38. # When they do, they have a case officer - I don't think we can
  39. # work out the other urls - even if they exist.
  40. # Best to use the email address.
  41. application.comment_url = self.comments_email_address
  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 = KingstonParser()
  48. print parser.getResults(2,8,2008)