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.

utils.py 3.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import datetime
  2. import sys
  3. from bs4 import BeautifulSoup
  4. import getpass
  5. from requests import get
  6. __author__ = "theycallmemac"
  7. __version__ = '2.0.0'
  8. __copyright__ = 'Copyright (c) 2018 theycallmemac'
  9. __license__ = 'GPL-3.0'
  10. def confirm():
  11. if int(sys.version[0]) < 3:
  12. conf = raw_input("\033[1;93m{0}\033[00m".format(
  13. "\nIs this information correct? (y/n): "))
  14. else:
  15. conf = input("\033[1;93m{0}\033[00m".format(
  16. "\nIs this information correct? (y/n): "))
  17. if conf == "y":
  18. return conf
  19. else:
  20. return "n"
  21. def check_args(week, day):
  22. if int(week) not in range(1, 53) or int(day) not in range(1, 7):
  23. print("\033[1;91m{0}\033[00m".format("Incorrect parameters passed."))
  24. sys.exit()
  25. else:
  26. pass
  27. def check_room(timetable_url):
  28. html = get(timetable_url, verify=False)
  29. soup = BeautifulSoup(html.text, "lxml")
  30. tr = soup.select('tr')
  31. return str(tr[12].getText().strip()) + " -> " + \
  32. str(tr[14].getText().strip())
  33. def get_lst(c, g, q, h, options):
  34. if options.computing:
  35. lst = c
  36. elif options.grattan:
  37. lst = g
  38. elif options.business:
  39. lst = q
  40. elif options.nursing:
  41. lst = h
  42. return lst
  43. def get_current_time(date):
  44. day = date.weekday()
  45. hour = date.hour
  46. minute = date.minute
  47. year, week_no, weekday = date.isocalendar()
  48. start = 36
  49. if week_no >= start:
  50. offset = -start
  51. else:
  52. offset = 52 - start
  53. week = week_no + offset - 1
  54. return str(week), str(day + 1), str(hour), str(minute)
  55. def get_version_email():
  56. if int(sys.version[0]) < 3:
  57. email = raw_input("\033[1;97m{0}\033[00m".format("Your gmail: "))
  58. password = getpass.getpass(
  59. "\033[1;97m{0}\033[00m".format("Your gmail password: "))
  60. your_name = raw_input("\033[1;97m{0}\033[00m".format("Your name: "))
  61. society = raw_input("\033[1;97m{0}\033[00m".format("Society name: "))
  62. return email, password, your_name, society
  63. else:
  64. email = input("\033[1;97m{0}\033[00m".format("Your gmail: "))
  65. password = getpass.getpass(
  66. "\033[1;97m{0}\033[00m".format("Your gmail password: "))
  67. your_name = input("\033[1;97m{0}\033[00m".format("Your name: "))
  68. society = input("\033[1;97m{0}\033[00m".format("Society name: "))
  69. return email, password, your_name, society
  70. def get_version_form():
  71. if int(sys.version[0]) < 3:
  72. name = raw_input("\033[1;97m{0}\033[00m".format("Your name: "))
  73. email = raw_input("\033[1;97m{0}\033[00m".format("Your email: "))
  74. number = raw_input("\033[1;97m{0}\033[00m".format("Your number: "))
  75. society = raw_input("\033[1;97m{0}\033[00m".format("Society name: "))
  76. return email, number, name, society
  77. else:
  78. name = input("\033[1;97m{0}\033[00m".format("Your name: "))
  79. email = input("\033[1;97m{0}\033[00m".format("Your email: "))
  80. number = input("\033[1;97m{0}\033[00m".format("Your number: "))
  81. society = input("\033[1;97m{0}\033[00m".format("Society name: "))
  82. return email, number, name, society