Automatically exported from code.google.com/p/planningalerts
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

104 rader
3.3 KiB

  1. import urllib2
  2. import urllib
  3. import urlparse
  4. import datetime
  5. import cookielib
  6. cookie_jar = cookielib.CookieJar()
  7. from BeautifulSoup import BeautifulSoup
  8. from PlanningUtils import PlanningApplication, \
  9. PlanningAuthorityResults, \
  10. getPostcodeFromText
  11. date_format = "%d-%m-%Y"
  12. class OcellaParser:
  13. def __init__(self,
  14. authority_name,
  15. authority_short_name,
  16. base_url,
  17. debug=False):
  18. self.authority_name = authority_name
  19. self.authority_short_name = authority_short_name
  20. self.base_url = base_url
  21. self.debug = debug
  22. self._results = PlanningAuthorityResults(self.authority_name, self.authority_short_name)
  23. def getResultsByDayMonthYear(self, day, month, year):
  24. search_date = datetime.date(year, month, day)
  25. # First get the search page
  26. get_request = urllib2.Request(self.base_url)
  27. get_response = urllib2.urlopen(get_request)
  28. cookie_jar.extract_cookies(get_response, get_request)
  29. get_soup = BeautifulSoup(get_response.read())
  30. # We need to find where the post action goes
  31. action = get_soup.form['action']
  32. session_id = get_soup.find('input', {'name': 'p_session_id'})['value']
  33. post_data = urllib.urlencode(
  34. [#('p_object_name', 'FRM_WEEKLY_LIST.DEFAULT.SUBMIT_TOP.01'),
  35. #('p_instance', '1'),
  36. #('p_event_type', 'ON_CLICK'),
  37. #('p_user_args', ''),
  38. ('p_session_id', session_id),
  39. #('p_page_url', self.base_url),
  40. ('FRM_WEEKLY_LIST.DEFAULT.START_DATE.01', '02-06-2008'), #search_date.strftime(date_format),
  41. ('FRM_WEEKLY_LIST.DEFAULT.END_DATE.01', '09-06-2008'),#search_date.strftime(date_format),
  42. #('FRM_WEEKLY_LIST.DEFAULT.PARISH.01', ''),
  43. ]
  44. )
  45. post_request = urllib2.Request(action, post_data)
  46. cookie_jar.add_cookie_header(post_request)
  47. post_request.add_header('Referer', self.base_url)
  48. post_response = urllib2.urlopen(post_request)
  49. import pdb;pdb.set_trace()
  50. # # From Breckland
  51. # p_object_name=FRM_WEEKLY_LIST.DEFAULT.SUBMIT_TOP.01
  52. # p_instance=1
  53. # p_event_type=ON_CLICK
  54. # p_user_args=
  55. # p_session_id=53573
  56. # p_page_url=http%3A%2F%2Fwplan01.intranet.breckland.gov.uk%3A7778%2Fportal%2Fpage%3F_pageid%3D33%2C30988%26_dad%3Dportal%26_schema%3DPORTAL
  57. # FRM_WEEKLY_LIST.DEFAULT.START_DATE.01=02-06-2008
  58. # FRM_WEEKLY_LIST.DEFAULT.END_DATE.01=09-06-2008
  59. # FRM_WEEKLY_LIST.DEFAULT.PARISH.01=
  60. # # Mine
  61. # p_object_name=FRM_WEEKLY_LIST.DEFAULT.SUBMIT_TOP.01
  62. # p_user_args=
  63. # FRM_WEEKLY_LIST.DEFAULT.START_DATE.01=21-05-2008
  64. # FRM_WEEKLY_LIST.DEFAULT.END_DATE.01=21-05-2008
  65. # p_session_id=53576
  66. # p_instance=1
  67. # p_page_url=http%3A%2F%2Fwplan01.intranet.breckland.gov.uk%3A7778%2Fportal%2Fpage%3F_pageid%3D33%2C30988%26_dad%3Dportal%26_schema%3DPORTAL
  68. # FRM_WEEKLY_LIST.DEFAULT.PARISH.01=
  69. # p_event_type=ON_CLICK
  70. def getResults(self, day, month, year):
  71. return self.getResultsByDayMonthYear(int(day), int(month), int(year)).displayXML()
  72. if __name__ == '__main__':
  73. parser = OcellaParser("Breckland Council", "Breckland", "http://wplan01.intranet.breckland.gov.uk:7778/portal/page?_pageid=33,30988&_dad=portal&_schema=PORTAL")
  74. print parser.getResults(21,5,2008)