Browse Source

updated version information

pull/18/head
theycallmemac 3 years ago
parent
commit
b6c921f358
11 changed files with 33 additions and 426 deletions
  1. +0
    -94
      scripts/builders.py
  2. +0
    -101
      scripts/checks.py
  3. +0
    -108
      scripts/controls.py
  4. +3
    -1
      scripts/dcurooms
  5. +0
    -114
      scripts/index.py
  6. +8
    -0
      scripts/lab_booking.py
  7. +6
    -1
      scripts/lookup.py
  8. +1
    -1
      scripts/main.py
  9. +6
    -1
      scripts/now.py
  10. +7
    -3
      scripts/room_booking.py
  11. +2
    -2
      setup.py

+ 0
- 94
scripts/builders.py View File

@@ -1,94 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# import libraries
import sys
import datetime
import smtplib
from optparse import OptionParser
from mechanicalsoup import StatefulBrowser
from requests import get
from bs4 import BeautifulSoup
sys.path.append('.')
from scripts import checks
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '1.0.0'
__copyright__ = 'Copyright (c) 2017 theycallmemac'
__license__ = 'GPL-3.0'

def build_timetable(room, week, day, hour):
browser = StatefulBrowser()
cookie_jar = LWPCookieJar()
browser.set_cookiejar(cookie_jar)
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://www.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]
name, person, email, number = checks.check_version("form")
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 make_booking(form):
request = form.request
response = form.submit_selected()
return "Form submitted successfully."


def draft_email(args):
gmail_user, gmail_password, name, person = checks.check_version("email")
FROM = gmail_user
TO = ['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_credentials, FROM, TO, message):
try:
gmail_user, gmail_password = gmail_credentials[0], gmail_credentials[1]
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 BaseException:
print("Email failed to send.")


+ 0
- 101
scripts/checks.py View File

@@ -1,101 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# import libraries
import sys
import datetime
import smtplib
from optparse import OptionParser
from mechanicalsoup import StatefulBrowser
from requests import get
from bs4 import BeautifulSoup
sys.path.append('.')
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '1.0.0'
__copyright__ = 'Copyright (c) 2017 theycallmemac'
__license__ = 'GPL-3.0'

def check_arguments(week, day):
if int(week) not in range(1, 53) or int(day) not in range(1, 7):
print("Incorrect parameters passed.")
sys.exit()
else:
pass
def email_version():
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: ")
return gmail_user, gmail_password, name, person

def form_version():
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: ")
return name, person, email, number

def check_version(func):
if func == "email":
return email_version()
if func =="form":
return form_version()


def search_dictionary(times, time):
if time not in times:
print("Outside scheduled timetables. Please try again at 08:00.")
sys.exit()
for k, v in times.items():
if k == time:
time = v
break
else:
pass
return time

def get_current_time(date):
day = date.weekday()
hour = date.hour
minute = date.minute
year, week_no, weekday = date.isocalendar()
start = 36
if week_no >= start:
offset = -start
else:
offset = 52 - start
week = week_no + offset - 1
return str(week), str(day + 1), str(hour), str(minute)

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 get_confirmation():
if sys.version_info[0] < 3:
confirmation = raw_input("\nIs this the correct information? (y/n): ").lower()
else:
confirmation = input("\nIs this the correct information? (y/n): ").lower()
return confirmation


+ 0
- 108
scripts/controls.py View File

@@ -1,108 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# import libraries
import sys
import datetime
import smtplib
from optparse import OptionParser
from mechanicalsoup import StatefulBrowser
from requests import get
from bs4 import BeautifulSoup
sys.path.append('.')
from scripts import builders
from scripts import checks
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '1.0.0'
__copyright__ = 'Copyright (c) 2017 theycallmemac'
__license__ = 'GPL-3.0'

def get_statuses(status, options, room):
if options.available:
if len(status) <= 9:
print(room + ": " + status)
else:
print(room + ": " + status)

def run_loop(lst, options, details):
week, day, time = details[0:3]
for room in lst:
timetable, url = builders.build_timetable("GLA." + room, week, day, time)
status = checks.check_room(url)
get_statuses(status, options, room)

def book_grattan(details):
form = builders.fill_form(details)
conf = checks.get_confirmation()
if conf == "y":
room_booked = builders.make_booking(form)
print(room_booked)
else:
print("Form submission withdrawn.")
sys.exit()

def book_computing(details):
creds = []
user, password, from_who, to_who, message = builders.draft_email(details)
creds = [user, password]
conf = checks.get_confirmation()
if conf == "y":
builders.send_email(creds, from_who, to_who, message)
else:
print("Draft withdrawn.")
sys.exit()

def booking_control(c, g, details):
if details[0] in c:
book_computing(details)
elif details[0] in g:
book_grattan(details)
else:
print("That room is not supported by this tool.")
sys.exit()

def lookup_room_control(g, c, details, times):
if len(details) <= 3:
print("Not enough arguments passed.")
sys.exit()
room, week = details[0:2]
day, time = details[2:4]
if room not in g and room not in c:
print("That room is not supported by this program.")
sys.exit()
checks.check_arguments(week, day)
time = checks.search_dictionary(times, time)
timetable, url = builders.build_timetable("GLA." + room, week, day, time)
status = checks.check_room(url)
print(room + ": " + status)
sys.exit()

def lookup_building_control(options, lst, details, times):
week, day, time = details[0:3]
checks.check_arguments(week, day)
time = checks.search_dictionary(times, time)
details =[week, day, time]
run_loop(lst, options, details)
sys.exit()

def available_now_control(options, lst, times):
week, day, hour, minute = checks.get_current_time(datetime.datetime.now())
if int(hour) < 8 or int(hour) >= 23:
print("Outside scheduled timetables. Try again at 08:00.")
sys.exit()
if int(minute) >= 30:
minute = '30'
else:
minute = '00'
checks.check_arguments(int(week), int(day))
time = checks.search_dictionary(times, hour + minute)
details = [week, day, time]
run_loop(lst, options, details)
sys.exit()



+ 3
- 1
scripts/dcurooms View File

@@ -1,6 +1,8 @@
import main

__author__ = "theycallmemac"
__version__ = '2.0.0'
__author__ = 'theycallmemac'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'

main.main()

+ 0
- 114
scripts/index.py View File

@@ -1,114 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# import libraries
import sys
import datetime
import smtplib
from optparse import OptionParser
from mechanicalsoup import StatefulBrowser
from requests import get
from bs4 import BeautifulSoup
sys.path.append(".")
from scripts import controls
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '1.0.0'
__copyright__ = 'Copyright (c) 2017 theycallmemac'
__license__ = 'GPL-3.0'

def setup_options():
parser = OptionParser(
description='Displays info and books room around DCU.',
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="books a room by providing the room, D/M/YYYY, start, and end")
parser.add_option(
"-a", "--available", action="store_true",
help="returns only the rooms/labs that are free in a building")
parser.add_option(
"-n", "--now", action="store_true",
help="show the status of each room/lab as it is currently")
# 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 get_data():
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:]
return times, c, g, details

def get_lst(c, g, options):
if options.computing: lst = c
elif options.grattan: lst = g
return lst

def opt_is_room(options, rooms, details, times):
c, g = rooms[0:2]
if options.computing: lst = c
elif options.grattan: lst = g
else:
controls.lookup_room_control(g, c, details, times)


def booking_option(rooms, details):
c, g = rooms[0:2]
print("Booking requires more arguments. See the help for details.") if len(details) < 4 else controls.booking_control(c, g, details)
sys.exit()




def lookup_option(options, rooms, details, times):
opt_is_room(options, rooms, details, times)
lst = get_lst(rooms[0], rooms[1], options)
controls.lookup_building_control(options, lst, details, times)

def now_option(options, rooms, times):
c, g = rooms[0:2]
lst = get_lst(c, g, options)
controls.available_now_control(options, lst, times)

def required():
parser = setup_options()
(options, arguments) = parser.parse_args()
times, c, g, details = get_data()
return parser, (options, arguments), (c, g), (times, details)

def requesting_booking(options, rooms, details):
if options.book and len(details) < 5:
booking_option(rooms, details)
else:
pass

def displaying_info(options, rooms, details, times):
if options.lookup:
lookup_option(options, rooms, details, times)
elif options.now:
now_option(options, rooms, times)

def flow(options, rooms, info):
times, details = info[0:2]
requesting_booking(options, rooms, details)
displaying_info(options, rooms, details, times)

def main():
parser, (options, arguments), rooms, info = required()
flow(options, rooms, info)
parser.print_help()
if __name__ == '__main__':
main()


+ 8
- 0
scripts/lab_booking.py View File

@@ -1,5 +1,13 @@
import sys
import smtplib


__author__ = "theycallmemac"
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'


class LabBooking(object):
arguments = []
email= ""


+ 6
- 1
scripts/lookup.py View File

@@ -1,8 +1,13 @@
import sys
from mechanicalsoup import StatefulBrowser
from http.cookiejar import LWPCookieJar
from requests import get
from bs4 import BeautifulSoup

if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'


+ 1
- 1
scripts/main.py View File

@@ -11,7 +11,7 @@ from lookup import LookUp
from now import Now

__author__ = "theycallmemac"
__version__ = '1.0.0'
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'



+ 6
- 1
scripts/now.py View File

@@ -1,9 +1,14 @@
import sys
from mechanicalsoup import StatefulBrowser
from http.cookiejar import LWPCookieJar
from requests import get
from bs4 import BeautifulSoup

if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar


__author__ = "theycallmemac"
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'


+ 7
- 3
scripts/room_booking.py View File

@@ -1,11 +1,15 @@
import sys
from mechanicalsoup import StatefulBrowser
from http.cookiejar import LWPCookieJar
from requests import get

if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
from http.cookiejar import LWPCookieJar

__author__ = "theycallmemac"
__version__ = '1.0.0'
__copyright__ = 'Copyright (c) 2017 theycallmemac'
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'

class RoomBooking(object):


+ 2
- 2
setup.py View File

@@ -2,12 +2,12 @@
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(name='dcurooms',
version='1.0.0',
version='2.0.0',
description='Shows room information around the DCU campus',
author='theycallmemac',
url='https://github.com/theycallmemac/dcurooms',
license='GPL-3.0',
scripts=['scripts/dcurooms', 'scripts/index.py', 'scripts/controls.py', 'scripts/builders.py', 'scripts/checks.py'],
scripts=['scripts/dcurooms', 'scripts/main.py', 'scripts/lab_booking.py', 'scripts/room_booking.py', 'scripts/lookup.py', 'scripts/now.py'],
install_requires=[
'MechanicalSoup', 'bs4', 'requests'
],


Loading…
Cancel
Save