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.

79 lines
3.1 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('Displays info and books room around DCU.'),
  20. prog="\033[1;97m{0}\033[00m".format('dcurooms'), version='%prog ' + __version__, usage='%prog [' + '\033[1;92m{0}\033[00m'.format("option") + ']')
  21. parser.add_option(
  22. "-l", "--lookup", action="store_true", help="returns information given a specific room, week, day and hour")
  23. parser.add_option(
  24. "-b", "--book", action="store_true",
  25. help="books a room by providing the room, D/M/YYYY, start, and end")
  26. parser.add_option(
  27. "-a", "--available", action="store_true",
  28. help="returns only the rooms/labs that are free in a building")
  29. parser.add_option(
  30. "-n", "--now", action="store_true",
  31. help="show the status of each room/lab as it is currently")
  32. # building options which can be passed
  33. parser.add_option(
  34. "-L", "--computing", action="store_true",
  35. help="displays the status of the labs in the School of Computing")
  36. parser.add_option(
  37. "-C", "--grattan", action="store_true",
  38. help="displays the status of rooms in the Henry Grattan building")
  39. return parser
  40. def get_data():
  41. 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:]
  42. return times, c, g, details
  43. def required():
  44. parser = setup_options()
  45. (options, arguments) = parser.parse_args()
  46. times, c, g, details = get_data()
  47. return parser, (options, arguments), (c, g), (times, details)
  48. def booking(options, info):
  49. if options.book and info[1][0][0] == "L":
  50. opts.booking_lab(info)
  51. elif options.book and info[1][0][0] == "C":
  52. opts.booking_room(info)
  53. def lookup(options, rooms, info):
  54. if options.lookup and (options.grattan or options.computing):
  55. opts.lookup_building(rooms, info, options)
  56. elif options.lookup:
  57. opts.lookup_room(info)
  58. def now(options, rooms, info):
  59. opts.now(rooms, info, options)
  60. def main():
  61. parser, (options, arguments), rooms, info = required()
  62. if options.book:
  63. booking(options, info)
  64. elif options.lookup:
  65. lookup(options, rooms, info)
  66. elif options.now:
  67. now(options, rooms, info)
  68. if __name__ == "__main__":
  69. main()