A mirror of dcurooms found at https://github.com/theycallmemac/dcurooms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

  1. import sys
  2. from mechanicalsoup import StatefulBrowser
  3. from requests import get
  4. from bs4 import BeautifulSoup
  5. import utils
  6. from termcolor import colored
  7. if sys.version_info[0] < 3:
  8. from cookielib import LWPCookieJar
  9. else:
  10. from http.cookiejar import LWPCookieJar
  11. __author__ = "theycallmemac"
  12. __version__ = '2.0.0'
  13. __copyright__ = 'Copyright (c) 2018 theycallmemac'
  14. __license__ = 'GPL-3.0'
  15. class LookUp(object):
  16. week = ""
  17. day = ""
  18. hour = ""
  19. def __init__(self, week, day, hour):
  20. self.week = week
  21. self.day = day
  22. self.hour = hour
  23. def check_time(self, times):
  24. if self.hour not in times:
  25. print("Outside scheduled timetables. Please try again at 08:00.")
  26. sys.exit()
  27. for k, v in times.items():
  28. if k == self.hour:
  29. self.hour = v
  30. break
  31. else:
  32. pass
  33. def building_option(self, lst):
  34. for room in lst:
  35. status = LookUp.build_timetable(self, room)
  36. if len(status) <= 9:
  37. print("\033[1;92m{0}\033[00m".format(room) + ": " + "\033[1;97m{0}\033[00m".format(status))
  38. else:
  39. print("\033[1;91m{0}\033[00m".format(room) + ": " + "\033[1;90m{0}\033[00m".format(status))
  40. def room_option(self, room):
  41. status = LookUp.build_timetable(self, room)
  42. print(room + ": " + status)
  43. def build_timetable(self, room):
  44. browser = StatefulBrowser()
  45. cookie_jar = LWPCookieJar()
  46. browser.set_cookiejar(cookie_jar)
  47. browser.user_agent = [
  48. ("User-Agent",
  49. """Mozilla/5.0 (Windows NT 10.0; Win64; x64)
  50. AppleWebKit/537.36 (KHTML, like Gecko)
  51. Chrome/58.0.3029.110
  52. Safari/537.36""")]
  53. url = "https://www.dcu.ie/timetables/feed.php?room=GLA." + room + "&week1=" + self.week + "&hour=" + str(self.hour) + "&day=" + self.day + "&template=location"
  54. browser.open(url)
  55. result = utils.check_room(url)
  56. return result