44
55ALL_URL = 'https://www.laundryalert.com/cgi-bin/penn6389/LMPage?Login=True'
66HALL_BASE_URL = 'https://www.laundryalert.com/cgi-bin/penn6389/LMRoom?Halls='
7+ USAGE_BASE_URL = 'https://www.laundryalert.com/cgi-bin/penn6389/LMRoomUsage?CallingPage=LMRoom&Password=penn6389&Halls='
78
89
910class Laundry (object ):
@@ -16,7 +17,16 @@ class Laundry(object):
1617 """
1718
1819 def __init__ (self ):
19- pass
20+ self .busy_dict = {
21+ 'LowBusyNightColor' : 'Low' ,
22+ 'LowBusyDayColor' : 'Low' ,
23+ 'MediumLowBusyColor' : 'Medium' ,
24+ 'MediumHighBusyColor' : 'High' ,
25+ 'HighBusyColor' : 'Very High' ,
26+ 'NoDataBusyColor' : 'No Data'
27+ }
28+ self .days = ['Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' ,
29+ 'Saturday' , 'Sunday' ]
2030
2131 @staticmethod
2232 def get_hall_no (href ):
@@ -116,4 +126,39 @@ def to_dict(data_row):
116126 d ['time_left' ] = None
117127 return d
118128
119- return {'machines' : list (map (to_dict , data_improved )), 'hall_name' : hall_name }
129+ return {
130+ 'machines' : list (map (to_dict , data_improved )),
131+ 'hall_name' : hall_name
132+ }
133+
134+ def machine_usage (self , hall_no ):
135+ """Returns the average usage of laundry machines every hour
136+ for a given hall.
137+
138+ The usages are returned in a dictionary, with the key being
139+ the day of the week, and the value being an array listing the usages
140+ per hour.
141+
142+ :param hall_no:
143+ integer corresponding to the id number for the hall. Thus number
144+ is returned as part of the all_status call.
145+
146+ >>> english_house = l.machine_usage(2)
147+ """
148+
149+ try :
150+ num = int (hall_no )
151+ except ValueError :
152+ raise ValueError ("Room Number must be integer" )
153+ r = requests .get (USAGE_BASE_URL + str (num ))
154+ parsed = BeautifulSoup (r .text , 'html5lib' )
155+ usage_table = parsed .find_all ('table' , width = '504px' )[0 ]
156+ rows = usage_table .find_all ('tr' )
157+ usages = {}
158+ for i , row in enumerate (rows ):
159+ day = []
160+ hours = row .find_all ('td' )
161+ for hour in hours :
162+ day .append (self .busy_dict [str (hour ['class' ][0 ])])
163+ usages [self .days [i ]] = day
164+ return usages
0 commit comments