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.

98 lines
3.6 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # import libraries
  4. import sys
  5. import datetime
  6. import smtplib
  7. from optparse import OptionParser
  8. from mechanicalsoup import StatefulBrowser
  9. from requests import get
  10. from bs4 import BeautifulSoup
  11. sys.path.append(".")
  12. from scripts import controls
  13. if sys.version_info[0] < 3:
  14. from cookielib import LWPCookieJar
  15. else:
  16. from http.cookiejar import LWPCookieJar
  17. __author__ = "theycallmemac"
  18. __version__ = '1.0.0'
  19. __copyright__ = 'Copyright (c) 2017 theycallmemac'
  20. __license__ = 'GPL-3.0'
  21. def setup_options():
  22. parser = OptionParser(
  23. description='Displays info and books room around DCU.',
  24. prog='dcurooms', version='%prog ' + __version__,
  25. usage='%prog [option]')
  26. parser.add_option(
  27. "-l", "--lookup", action="store_true",
  28. help="returns information given a specific room, week, day and hour")
  29. parser.add_option(
  30. "-b", "--book", action="store_true",
  31. help="books a room by providing the room, D/M/YYYY, start, and end")
  32. parser.add_option(
  33. "-a", "--available", action="store_true",
  34. help="returns only the rooms/labs that are free in a building")
  35. parser.add_option(
  36. "-n", "--now", action="store_true",
  37. help="show the status of each room/lab as it is currently")
  38. # building options which can be passed
  39. parser.add_option(
  40. "-L", "--computing", action="store_true",
  41. help="displays the status of the labs in the School of Computing")
  42. parser.add_option(
  43. "-C", "--grattan", action="store_true",
  44. help="displays the status of rooms in the Henry Grattan building")
  45. return parser
  46. def get_data():
  47. times, c, g, details = {'0800': '1', '0830': '2', '0900': '3', '0930': '4', '1000': '5', '1030': '6', '1100': '7', '1130': '8', '1200': '9', '1230': '10', '1300': '11', '1330': '12', '1400': '13','1430': '14', '1500': '15', '1530': '16', '1600': '17', '1630': '18', '1700': '19', '1730': '20', '1800': '21', '1830': '22', '1900': '23', '1930': '24', '2000': '25', '2030': '26', '2100': '27', '2130': '28', '2200': '29', '2230': '30'}, ['LG25', 'LG26', 'LG27', 'L101', 'L114', 'L125', 'L128'], ['CG01', 'CG02', 'CG03', 'CG04', 'CG05', 'CG06', 'CG11', 'CG12', 'CG20', 'CG68', 'C166'], sys.argv[2:]
  48. return times, c, g, details
  49. def get_lst(c, g, options):
  50. if options.computing: lst = c
  51. elif options.grattan: lst = g
  52. return lst
  53. def opt_is_room(options, rooms, details, times):
  54. c, g = rooms[0:2]
  55. if options.computing: lst = c
  56. elif options.grattan: lst = g
  57. else:
  58. controls.lookup_room_control(g, c, details, times)
  59. def booking_option(c, g, details):
  60. print("Booking requires more arguments. See the help for details.") if len(details) < 4 else controls.booking_control(c, g, details)
  61. sys.exit()
  62. def lookup_option(options, rooms, details, times):
  63. opt_is_room(options, rooms, details, times)
  64. lst = get_lst(rooms[0], rooms[1], options)
  65. controls.lookup_building_control(options, lst, details, times)
  66. def now_option(options, c, g, times):
  67. lst = get_lst(c, g, options)
  68. controls.available_now_control(options, lst, times)
  69. def required():
  70. parser = setup_options()
  71. (options, arguments) = parser.parse_args()
  72. times, c, g, details = get_data()
  73. return parser, (options, arguments), times, c, g, details
  74. def main():
  75. parser, (options, arguments), times, c, g, details = required()
  76. if options.book and len(details) < 5:
  77. booking_option(c, g, details)
  78. elif options.lookup:
  79. lookup_option(options, (c, g), details, times)
  80. elif options.now:
  81. now_option(options, c, g, times)
  82. parser.print_help()
  83. if __name__ == '__main__':
  84. main()