Browse Source

booking option added - closes #3

pull/18/head
theycallmemac 3 years ago
parent
commit
8cea25aac9
5 changed files with 150 additions and 14 deletions
  1. +24
    -0
      CHANGELOG.md
  2. +10
    -5
      README.md
  3. +1
    -1
      scripts/dcurooms
  4. +114
    -7
      scripts/dcurooms.py
  5. +1
    -1
      setup.py

+ 24
- 0
CHANGELOG.md View File

@@ -75,6 +75,7 @@ __entry:__ 14-12-2017
__contributor:__ theycallmemac

---

- .gitignore
- created to ignore .pyc and .txt files
- also ignores egg-info aswell as build and dist directories
@@ -104,6 +105,7 @@ __entry:__ 16-12-2017
__contributor:__ theycallmemac

---

- scripts/dcurooms.py
- now at v0.3.0 due to some minor changes in what the tool can do and it's usage.
- can now look up specific rooms on any given week and timeslot.
@@ -122,6 +124,7 @@ __contributor:__ theycallmemac
- tests the -anc options rather that the previous -fnc options.
- renamed file and changed some names around the test.
- fixed issue #2

---

---
@@ -130,6 +133,7 @@ __entry:__ 19-12-2017
__contributor:__ theycallmemac

---

- scripts/dcurooms.py
- now at v0.4.0 because of some rewrites and added functionality
- lookup option now supports a lookup when available option, given as "-la"/"--lookup --available"
@@ -146,6 +150,7 @@ __contributor:__ theycallmemac
- tests/test_available_now.py
- removed unnecessary lines
- changed information and created txt file based on new option names from v0.3.0

---

---
@@ -154,6 +159,7 @@ __entry:__ 20-12-2017
__contributor:__ theycallmemac

---

- scripts/dcurooms.py
- now at v0.4.2
- Refactored script from 214 lines to 149 lines, removing large blocks of repetitive code
@@ -161,10 +167,13 @@ __contributor:__ theycallmemac

---

---

__entry:__ 21-12-2017
__contributor:__ theycallmemac

---

- scripts/dcurooms.py
- made dcurooms compatible with python3.x, thus closing issue #6
- this was done by using MechanicalSoup instead of mechanize as the former supports python2 and python3
@@ -172,5 +181,20 @@ __contributor:__ theycallmemac

- setup.py
- included more info on the versions of python that the dcurooms script supports

---

---

__entry:__ 24-12-2017
__contributor:__ theycallmemac

---

- scripts/dcurooms.py
- closes #3, milestone 1.0.0 reached
- supports the booking of rooms in the Henry Grattan Building and labs in the School of Computing.
- requires your gmail username and password to send lab booking on behalf of your email.
- supports both python2 and python3

---

+ 10
- 5
README.md View File

@@ -19,15 +19,20 @@ cd into the clone and run ```python setup.py install``` as root to install.


### Usage
To check the current availabilty of labs in the DCU School of Computing run ```dcurooms -nc``` or ```dcurooms --now --computing```.
Buildings are referenced using their assigned building letters. The School of Computing is given the letter "L" and the Henry Grattan is given the letter "C". Don't ask me why it's like that, it's a very odd naming convention.

To show the rooms which are currently available in the Henry Grattan building run ```dcurooms -anc``` or ```dcurooms --available --now --computing```.
To book L125 in the School of Computing on the 7/2/2018 from 16:00 to 17:00, run ```dcurooms -b L125 7/2/2018 1600 1700```.

To display the information of a specific room in the Henry Grattan building at 16:00 on the Monday of the 4th week of the college year run ```dcurooms -l CG05 4 1 1600``` or ```dcurooms --lookup CG05 4 1 1600```.
To book CG04 in the Henry Grattan on the 5/2/2018 from 18:00 to 20:00, run ```dcurooms -b CG04 5/2/2018 1800 2000```.

To check the current availabilty of labs in the DCU School of Computing run ```dcurooms -nL``` or ```dcurooms --now --computing```.

To look up the info of all rooms in the School of Computing at 13:00 on the Thursday of the 10th week of the college year run ```dcurooms -lc 10 4 1300``` or ```dcurooms --lookup --computing 10 4 1300```.
To show the rooms which are currently available in the Henry Grattan building run ```dcurooms -anC``` or ```dcurooms --available --now --grattan```.

To display the information of a specific room in the Henry Grattan building at 16:00 on the Monday of the 4th week of the college year run ```dcurooms -l CG05 4 1 1600``` or ```dcurooms --lookup CG05 4 1 1600```.

To lookup the info of all free rooms in the Henry Grattan building at 16:00 on the Monday of the 21st week of the college year run ```dcurooms -lac 21 1 1600``` or ```dcurooms --lookup --available --computing 21 4 1600```.
To look up the info of all rooms in the School of Computing at 13:00 on the Thursday of the 10th week of the college year run ```dcurooms -lL 10 4 1300``` or ```dcurooms --lookup --computing 10 4 1300```

To lookup the info of all free rooms in the Henry Grattan building at 16:00 on the Monday of the 21st week of the college year run ```dcurooms -laC 21 1 1600``` or ```dcurooms --lookup --available --grattan 21 4 1600```.

For help run ```dcurooms -h``` and for the current version run ```dcurooms --version```.

+ 1
- 1
scripts/dcurooms View File

@@ -1,6 +1,6 @@
import dcurooms

__version__ = '0.4.2'
__version__ = '1.0.0'
__author__ = 'theycallmemac'

dcurooms.main()

+ 114
- 7
scripts/dcurooms.py View File

@@ -3,6 +3,7 @@

import datetime
import sys
import smtplib
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
@@ -18,13 +19,16 @@ __copyright__ = 'Copyright (c) 2017 theycallmemac'
__license__ = 'GPL-3.0'

def setup_options():
parser = OptionParser(description='Displays and books rooms around the DCU campus via provided timetable/module details', prog='dcurooms', version='%prog ' + __version__, usage='%prog [option]')
parser = OptionParser(description='Displays and books rooms around the DCU campus via provided timetable/module details', prog='dcurooms', version='%prog ' + __version__, usage='%prog [option]')
parser.add_option("-l", "--lookup", action="store_true", help="returns information given a specific room, week, day and hour")
parser.add_option("-b", "--book", action="store_true", help="book a room by providing the room, DD/MM/YYYY, start time, and end time")
parser.add_option("-a", "--available", action="store_true", help="returns only the rooms/labs that are free in a building")
parser.add_option("-l", "--lookup", action="store_true", help="returns information given a specific room, week, day and hour")
parser.add_option("-n", "--now", action="store_true", help="show the status of each room/lab as it is at the current time of checking")
parser.add_option("-c", "--computing", action="store_true", help="displays the status of the labs in the School of Computing")
parser.add_option("-g", "--grattan", action="store_true", help="displays the status of rooms in the Henry Grattan building")
return parser
# building options which can be passed
parser.add_option("-L", "--computing", action="store_true", help="displays the status of the labs in the School of Computing")
parser.add_option("-C", "--grattan", action="store_true", help="displays the status of rooms in the Henry Grattan building")

return parser

def check_arguments(week, day):
if int(week) not in range(1, 53) or int(day) not in range(1,7):
@@ -62,17 +66,86 @@ def build_timetable(room, week, day, hour):
browser = StatefulBrowser()
cookie_jar = LWPCookieJar()
browser.set_cookiejar(cookie_jar)
browser.addheaders = [("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")]
browser.user_agent = [("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")]
url = "https://www101.dcu.ie/timetables/feed.php?room=" + room + "&week1=" + week + "&hour=" + str(hour) + "&day=" + day + "&template=location"
browser.open(url)
return browser, url

def fill_form(args):
browser = StatefulBrowser()
cookie_jar = LWPCookieJar()
browser.set_cookiejar(cookie_jar)
room, date, from_time, to_time = args[0], args[1].split("/"), args[2][:2] + ":" + args[2][2:], args[3][:2] + ":" + args[3][2:]
day, month, year = date[0], date[1], date[2]
if sys.version_info[0] < 3:
name = raw_input("Name of society: ")
person = raw_input("Your name: ")
email = raw_input("Your email: ")
number = raw_input("Your number: ")
else:
name = input("Name of society: ")
person = (input("Your name: ")
email = input("Your email: ")
number = input("Your number: ")
browser.open("http://www.dcu.ie/registry/booking.shtml")
browser.select_form(nr=2)
browser["submitted[name_of_club_society]"] = name
browser["submitted[name_of_person_making_booking]"] = person
browser["submitted[contact_telephone_number]"] = number
browser["submitted[date_room_required][day]"] = day
browser["submitted[date_room_required][month]"] = month
browser["submitted[date_room_required][year]"] = year
browser["submitted[room_capacity]"] = "18"
browser["submitted[description_of_event]"] = "Meeting"
browser["submitted[hours_requiredfrom_to]"] = from_time + " - " + to_time
browser["submitted[building_room_reference]"] = room
browser["submitted[email_address]"] = email

return browser

def check_room(timetable_url):
html = get(timetable_url)
soup = BeautifulSoup(html.text, "lxml")
tr = soup.select('tr')
return str(tr[12].getText().strip()) + " -> " + str(tr[14].getText().strip())

def make_booking(form):
request = form.request
response = form.submit_selected()
return "Form submitted successfully."

def draft_email(args):
if sys.version_info[0] < 3:
gmail_user = raw_input("Your gmail: ")
gmail_password = raw_input("Your gmail password: ")
name = raw_input("Society name: ")
person = raw_input("Your name: ")
else:
gmail_user = input("Your gmail: ")
gmail_password = input("Your gmail password: ")
name = input("Society name: ")
person = input("Your name: ")
FROM = gmail_user
TO = 'irene.mcevoy@dcu.ie' if type('irene.mcevoy@dcu.ie') is list else ['irene.mcevoy@dcu.ie']
SUBJECT = 'Lab Booking'
BODY = "Just wondering if you could book " + args[0] + " on the " + args[1] + " from " + args[2][:2] + ":" + args[2][2:] + " to " + args[3][:2] + ":" + args[3][2:] + " for " + name + ".\n\nThank you,\n" + person + "."
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, BODY)

return gmail_user, gmail_password, FROM, TO, message

def send_email(gmail_user, gmail_password, FROM, TO, message):
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_password)
server.sendmail(FROM, TO, message)
server.close()
print("Your email has been sent.")
except:
print("Email failed to send.")

def main():
parser = setup_options()
(options, arguments) = parser.parse_args()
@@ -83,7 +156,41 @@ def main():
c = ['LG25','LG26','LG27','L101','L114','L125','L128']
g = ['CG01', 'CG02','CG03','CG04','CG05','CG06','CG11','CG12','CG20','CG68','C166']
details = sys.argv[2:]
if len(details) > 5:

if options.book == True:
if len(details) < 4:
print("Booking a room requires more arguments. See the help for details.")
sys.exit()
else:
if details[0] in c:
user, password, from_who, to_who, message = draft_email(details)
if sys.version_info[0] < 3:
confimation = raw_input("\nIs this the correct information? (y/n): ").lower()
else:
confirmation = input("\nIs this the correct information? (y/n): ").lower()
if confirmation == "y":
send_email(user, password, from_who, to_who, message)
else:
print("Draft withdrawn.")
sys.exit()

elif details[0] in g:
form = fill_form(details)
if sys.version_info[0] < 3:
confimation = raw_input("\nIs this the correct information? (y/n): ").lower()
else:
confirmation = input("\nIs this the correct information? (y/n): ").lower()
if confirmation == "y":
room_booked = make_booking(form)
print(room_booked)
else:
print("Form submission withdrawn.")
sys.exit()
else:
print("That room is not supported by this tool.")
sys.exit()

elif len(details) > 5:
print("Too many arguments passed.")
sys.exit()
elif options.lookup == True:


+ 1
- 1
setup.py View File

@@ -3,7 +3,7 @@
from setuptools import setup
from setuptools import find_packages
setup(name='dcurooms',
version='0.4.2',
version='1.0.0',
description='Shows room information around the DCU campus',
author='theycallmemac',
url='https://github.com/theycallmemac/dcuroomsi',


Loading…
Cancel
Save