A mirror of dcurooms found at https://github.com/theycallmemac/dcurooms
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

58 linhas
2.0 KiB

  1. import sys
  2. from mechanicalsoup import StatefulBrowser
  3. from requests import get
  4. if sys.version_info[0] < 3:
  5. from cookielib import LWPCookieJar
  6. else:
  7. from http.cookiejar import LWPCookieJar
  8. __author__ = "theycallmemac"
  9. __version__ = '2.0.0'
  10. __copyright__ = 'Copyright (c) 2018 theycallmemac'
  11. __license__ = 'GPL-3.0'
  12. class RoomBooking(object):
  13. arguments = []
  14. email = ""
  15. number = ""
  16. name = ""
  17. society = ""
  18. def __init__(self, email, number, name, society, arguments):
  19. self.arguments = arguments
  20. self.email = email
  21. self.number = number
  22. self.name = name
  23. self.society = society
  24. def fill(self):
  25. browser = StatefulBrowser()
  26. cookie_jar = LWPCookieJar()
  27. browser.set_cookiejar(cookie_jar)
  28. room, date, start, end = self.arguments[0], self.arguments[1].split(
  29. "/"), self.arguments[2][:2] + ":" + \
  30. self.arguments[2][2:], self.arguments[3][:2] + \
  31. ":" + self.arguments[3][2:]
  32. day, month, year = date[0], date[1], date[2]
  33. browser.open("http://www.dcu.ie/registry/booking.shtml")
  34. browser.select_form(nr=4)
  35. browser["submitted[name_of_club_society]"] = self.society
  36. browser["submitted[name_of_person_making_booking]"] = self.name
  37. browser["submitted[contact_telephone_number]"] = self.number
  38. browser["submitted[date_room_required][day]"] = day
  39. browser["submitted[date_room_required][month]"] = month
  40. browser["submitted[date_room_required][year]"] = year
  41. browser["submitted[room_capacity]"] = "18"
  42. browser["submitted[description_of_event]"] = "Meeting"
  43. browser["submitted[hours_requiredfrom_to]"] = start + " - " + end
  44. browser["submitted[building_room_reference]"] = room
  45. browser["submitted[email_address]"] = self.email
  46. return browser
  47. def submit(self, form):
  48. request = form.request
  49. response = form.submit_selected()
  50. return "Form submitted successfully."