Browse Source

small patch to close #8

pull/18/head
theycallmemac 3 years ago
parent
commit
2d96ed4f3b
4 changed files with 60 additions and 112 deletions
  1. +13
    -0
      CHANGELOG.md
  2. +1
    -1
      scripts/dcurooms
  3. +45
    -110
      scripts/dcurooms.py
  4. +1
    -1
      setup.py

+ 13
- 0
CHANGELOG.md View File

@@ -148,3 +148,16 @@ __contributor:__ theycallmemac
- changed information and created txt file based on new option names from v0.3.0
---

---

__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
- this refactoring fixes issue #8

---


+ 1
- 1
scripts/dcurooms View File

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

__version__ = '0.4.1'
__version__ = '0.4.2'
__author__ = 'theycallmemac'

dcurooms.main()

+ 45
- 110
scripts/dcurooms.py View File

@@ -10,10 +10,19 @@ from requests import get
from bs4 import BeautifulSoup

__author__ = "theycallmemac"
__version__ = '0.4.1'
__version__ = '0.4.2'
__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.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

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.")
@@ -23,7 +32,7 @@ def check_arguments(week, day):

def search_dictionary(times, time):
if time not in times:
print("Outside scheduled timetables. Please try again at 08:00.")
print("uOutside scheduled timetables. Please try again at 08:00.")
sys.exit()
for k,v in times.items():
if k == time:
@@ -31,7 +40,6 @@ def search_dictionary(times, time):
break
else:
pass

return time

def get_current_time(date):
@@ -47,7 +55,6 @@ def get_current_time(date):
week = week_no + offset - 1
return str(week), str(day + 1), str(hour), str(minute)


def build_timetable(room, week, day, hour):
browser = Browser()
cookie_jar = LWPCookieJar()
@@ -69,92 +76,24 @@ def check_room(timetable_url):
tr = soup.select('tr')
return str(tr[12].getText().strip()) + " -> " + str(tr[14].getText().strip())


def main():
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("-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")
parser = setup_options()
(options, arguments) = parser.parse_args()
times = {'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'}
times = {'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'
}
c = ['LG25','LG26','LG27','L101','L114','L125','L128']
g = ['CG01', 'CG02','CG03','CG04','CG05','CG06','CG11','CG12','CG20','CG68','C166']
if options.lookup == True:
details = sys.argv[2:]
if len(details) > 5:
print("Too many arguments passed.")
sys.exit()
elif options.computing == True:
if options.available == True:
week, day, time = details[0], details[1], details[2]
check_arguments(week, day)
time = search_dictionary(times, time)
for room in c:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if len(status) <= 9:
print(room + ": " + status)
sys.exit()
else:
week, day, time = details[0], details[1], details[2]
check_arguments(week, day)
time = search_dictionary(times, time)
for room in c:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
print(room + ": " + status)
sys.exit()
details = sys.argv[2:]
if len(details) > 5:
print("Too many arguments passed.")
sys.exit()
elif options.lookup == True:
if options.computing == True:
lst = c
elif options.grattan == True:
if options.available == True:
week, day, time = details[0], details[1], details[2]
check_arguments(week, day)
time = search_dictionary(times, time)
for room in g:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if len(status) <= 9:
print(room + ": " + status)
sys.exit()
else:
week, day, time = details[0], details[1], details[2]
check_arguments(week, day)
time = search_dictionary(times, time)
for room in g:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
print(room + ": " + status)
sys.exit()
lst = g
else:
if len(details) <= 3:
print("Not enough arguments passed.")
@@ -169,7 +108,19 @@ def main():
status = check_room(url)
print(room + ": " + status)
sys.exit()
if options.now == True:
week, day, time = details[0], details[1], details[2]
check_arguments(week, day)
time = search_dictionary(times, time)
for room in lst:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if options.available == True:
if len(status) <= 9:
print(room + ": " + status)
else:
print(room + ": " + status)
sys.exit()
elif options.now == True:
week, day, hour, minute = get_current_time(datetime.datetime.now())
if int(hour) < 8 or int(hour) >= 23:
print("Outside scheduled timetables. Try again at 08:00.")
@@ -181,33 +132,17 @@ def main():
check_arguments(week, day)
time = search_dictionary(times, hour + minute)
if options.computing == True:
if options.available == True:
for room in c:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if len(status) <= 9:
print(room + ": " + status)
else:
for room in c:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
print(room + ": " + status)

lst = c
elif options.grattan == True:
lst = g
for room in lst:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if options.available == True:
for room in g:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
if len(status) <= 9:
print(room + ": " + status)
if len(status) <= 9:
print(room + ": " + status)
else:
for room in g:
timetable, url = build_timetable("GLA." + room, week, day, time)
status = check_room(url)
print(room + ": " + status)
else:
parser.print_help()
print(room + ": " + status)
else:
parser.print_help()
if __name__ == '__main__':


+ 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.1',
version='0.4.2',
description='Shows room information around the DCU campus',
author='theycallmemac',
url='https://github.com/theycallmemac/dcuroomsi',


Loading…
Cancel
Save