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.

115 lines
3.7 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # import libraries
  4. import sys
  5. import datetime
  6. from optparse import OptionParser
  7. from lab_booking import LabBooking
  8. from room_booking import RoomBooking
  9. from lookup import LookUp
  10. from now import Now
  11. import utils
  12. import opts
  13. __author__ = "theycallmemac"
  14. __version__ = '2.0.0'
  15. __copyright__ = 'Copyright (c) 2018 theycallmemac'
  16. __license__ = 'GPL-3.0'
  17. def setup_options():
  18. parser = OptionParser(
  19. description="\033[1;97m{0}\033[00m".format(
  20. 'Displays info and books room around DCU.'),
  21. prog="\033[1;97m{0}\033[00m".format('dcurooms'),
  22. version='%prog ' + __version__,
  23. usage='%prog [' + '\033[1;92m{0}\033[00m'.format("option") + ']')
  24. parser.add_option(
  25. "-l",
  26. "--lookup",
  27. 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. parser.add_option(
  46. "-H", "--nursing", action="store_true",
  47. help="displays the status of rooms in the Nursing building")
  48. parser.add_option(
  49. "-Q", "--business", action="store_true",
  50. help="displays the status of rooms in the Business building")
  51. return parser
  52. def get_data():
  53. times = {'0800': '1', '0830': '2', '0900': '3',
  54. '0930': '4', '1000': '5', '1030': '6',
  55. '1100': '7', '1130': '8', '1200': '9',
  56. '1230': '10', '1300': '11', '1330': '12',
  57. '1400': '13', '1430': '14', '1500': '15',
  58. '1530': '16', '1600': '17', '1630': '18',
  59. '1700': '19', '1730': '20', '1800': '21',
  60. '1830': '22', '1900': '23', '1930': '24',
  61. '2000': '25', '2030': '26', '2100': '27',
  62. '2130': '28', '2200': '29', '2230': '30'}
  63. c = ['LG25', 'LG26', 'LG27', 'L101', 'L114', 'L125', 'L128']
  64. g = ['CG01', 'CG02', 'CG03', 'CG04', 'CG05', 'CG06', 'CG11',
  65. 'CG12', 'CG20', 'CG68', 'CG86', 'C166']
  66. q = ["QG21", "QG22", "Q121", "Q122"]
  67. h = ["HG20", "HG22", "HG23"]
  68. details = sys.argv[2:]
  69. return times, c, g, q, h, details
  70. def required():
  71. parser = setup_options()
  72. (options, arguments) = parser.parse_args()
  73. times, c, g, q, h, details = get_data()
  74. return parser, (options, arguments), (c, g, q, h), (times, details)
  75. def booking(options, info):
  76. if options.book and info[1][0][0] == "L":
  77. opts.booking_lab(info)
  78. elif options.book and info[1][0][0] == "C":
  79. opts.booking_room(info)
  80. def lookup(options, rooms, info):
  81. if options.lookup and (options.grattan or options.computing or options.nursing or options.business):
  82. opts.lookup_building(rooms, info, options)
  83. elif options.lookup:
  84. opts.lookup_room(info)
  85. def now(options, rooms, info):
  86. opts.now(rooms, info, options)
  87. def main():
  88. parser, (options, arguments), rooms, info = required()
  89. if options.book:
  90. booking(options, info)
  91. elif options.lookup:
  92. lookup(options, rooms, info)
  93. elif options.now:
  94. now(options, rooms, info)
  95. if __name__ == "__main__":
  96. main()