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.
 
 
 
 
 
 

102 líneas
3.1 KiB

  1. __auth__ = None
  2. import re
  3. date_format = "%d/%m/%Y"
  4. def xmlQuote(text):
  5. # Change &s to &s
  6. # I suspect there is probably some standard python
  7. # function I should be using for this...
  8. return text.replace('&', '&')
  9. def fixNewlines(text):
  10. # This can be used to sort out windows newlines
  11. return text.replace("\r\n","\n")
  12. # So what can a postcode look like then?
  13. # This list of formats comes from http://www.mailsorttechnical.com/frequentlyaskedquestions.cfm
  14. #AN NAA M1 1AA
  15. #ANN NAA M60 1NW
  16. #AAN NAA CR2 6XH
  17. #AANN NAA DN55 1PT
  18. #ANA NAA W1A 1HP
  19. #AANA NAA EC1A 1BB
  20. postcode_regex = re.compile("[A-Z][A-Z]?\d(\d|[A-Z])? ?\d[A-Z][A-Z]")
  21. def getPostcodeFromText(text):
  22. """This function takes a piece of text and returns the first
  23. bit of it that looks like a postcode."""
  24. postcode_match = postcode_regex.search(text)
  25. if postcode_match is not None:
  26. return postcode_match.group()
  27. class PlanningAuthorityResults:
  28. """This class represents a set of results of a planning search.
  29. This should probably be separated out so that it can be used for
  30. authorities other than Cherwell.
  31. """
  32. def __init__(self, authority_name, authority_short_name):
  33. self.authority_name = authority_name
  34. self.authority_short_name = authority_short_name
  35. # this will be a list of PlanningApplication objects
  36. self.planning_applications = []
  37. def addApplication(self, application):
  38. self.planning_applications.append(application)
  39. def __repr__(self):
  40. return self.displayXML()
  41. def displayXML(self):
  42. """This should display the contents of this object in the planningalerts format.
  43. i.e. in the same format as this one:
  44. http://www.planningalerts.com/lambeth.xml
  45. """
  46. applications_bit = "".join([x.displayXML() for x in self.planning_applications])
  47. return "<planning>\n" +\
  48. "<authority_name>%s</authority_name>\n" %self.authority_name +\
  49. "<authority_short_name>%s</authority_short_name>\n" %self.authority_short_name +\
  50. "<applications>\n" + applications_bit +\
  51. "</applications>\n" +\
  52. "</planning>\n"
  53. class PlanningApplication:
  54. def __init__(self, no_postcode_default='No postcode'):
  55. self.council_reference = None
  56. self.address = None
  57. self.postcode = no_postcode_default
  58. self.description = None
  59. self.info_url = None
  60. self.comment_url = None
  61. # expecting this as a datetime.date object
  62. self.date_received = None
  63. def __repr__(self):
  64. return self.displayXML()
  65. def displayXML(self):
  66. return "<application>\n" +\
  67. "<council_reference>%s</council_reference>\n" %xmlQuote(self.council_reference) +\
  68. "<address>%s</address>\n" %xmlQuote(self.address) +\
  69. "<postcode>%s</postcode>\n" %self.postcode +\
  70. "<description>%s</description>\n" %xmlQuote(self.description) +\
  71. "<info_url>%s</info_url>\n" %xmlQuote(self.info_url) +\
  72. "<comment_url>%s</comment_url>\n" %xmlQuote(self.comment_url) +\
  73. "<date_received>%s</date_received>\n" %self.date_received.strftime(date_format) +\
  74. "</application>\n"