|
1 | 1 | #!/usr/bin/env python |
2 | 2 | #-*- coding:utf-8 -*- |
3 | 3 |
|
4 | | -## An one-file python library for study-booking system of CDUT Library. |
| 4 | +## An intensive python library for study-booking system of CDUT Library. |
5 | 5 | ## |
6 | 6 | ## This work is under Toay's PRE-MIT license with extra agreement that: |
7 | 7 | ## - to help protecting the server, rate limit must be setted below 1 rps |
@@ -45,14 +45,12 @@ def init(ignoreConnectionFault = False): |
45 | 45 | connectionResult = connection.connect_ex((socketIp, socketPort)) |
46 | 46 |
|
47 | 47 | if connectionResult != 0: |
48 | | - if (ignoreConnectionFault == False): |
| 48 | + if (ignoreConnectionFault == False or standbyMode != True): |
49 | 49 | print "remote server could not be connected, script exited :(" |
50 | 50 | connection.close() |
51 | 51 | sys.exit(0) |
52 | 52 | else: |
53 | | - if (standbyMode != True): |
54 | | - print "remote server could not be connected :(" |
55 | | - |
| 53 | + print "remote server could not be connected, ignoring :(" |
56 | 54 | connection.close() |
57 | 55 | excepted = "Exception_RemoteServerUnreachable" |
58 | 56 | return excepted |
@@ -223,43 +221,6 @@ def getUserInfoByCode(code = None, pretiffied = False): |
223 | 221 | generateTable = AsciiTable(tableData, tableTitle) |
224 | 222 | return generateTable.table |
225 | 223 |
|
226 | | -''' |
227 | | -
|
228 | | -# function: get the booking info for a specific room |
229 | | -
|
230 | | -def getRoomBookingInfo(roomId = None, prettified = False): |
231 | | - cookies = getFreshCookie() |
232 | | - if (roomId == None): |
233 | | - print "lacking parameters, function getRoomBookingInfo exited :(" |
234 | | - return False |
235 | | - else: |
236 | | - getRoomBookingInfoUrl = socketUrl + "datafeed" |
237 | | - parameters = {'method':'list', 'id':roomId} |
238 | | - getRoomBookingInfoResponse = requests.get(getRoomBookingInfoUrl, params = parameters) |
239 | | - roomBookingInfo = getRoomBookingInfoResponse |
240 | | - roomBookingInfoDict = roomBookingInfo.json() |
241 | | - roomBookingInfoJsonText = json.dumps(roomBookingInfoDict, ensure_ascii = False) |
242 | | - roomBookingInfoDict = json.load(roomBookingInfoDict) |
243 | | - roomBookingEvents = roomBookingInfo['events'] |
244 | | -
|
245 | | - if (prettified == False): |
246 | | - roomBookingTimeList = [] |
247 | | - for roomBookingEvent in roomBookingEvents: |
248 | | - roomBookTimeListEntry = { |
249 | | - 'start':roomBookingEvent[2], |
250 | | - 'end':roomBookingEvent[3] |
251 | | - } |
252 | | - roomBookTimeList.append(roomBookTimeListEntry) |
253 | | -
|
254 | | - roomBookingTimeListJson = json.dumps(roomBookingTimeList, ensure_ascii = False) |
255 | | - return roomBookingTimeListJson |
256 | | - else: |
257 | | - roomBookingTimeTable = [] |
258 | | - bookingEvents = roomBookingInfo['events'] |
259 | | - tableData = [['Start', 'End']] |
260 | | -
|
261 | | -''' |
262 | | - |
263 | 224 | # function: get the detailed booking information for a specific room |
264 | 225 |
|
265 | 226 | def getRoomBookingInfo(roomId = None, prettified = False, detailed = False): |
@@ -356,23 +317,6 @@ def getRoomBookingInfo(roomId = None, prettified = False, detailed = False): |
356 | 317 | generateTable = AsciiTable(tableData, tableTitle) |
357 | 318 | return generateTable.table |
358 | 319 |
|
359 | | -''' |
360 | | -
|
361 | | -# function: get the detailed booking info for all rooms |
362 | | -
|
363 | | -def getAllCurrentBookableRoomsInfo(): |
364 | | - global kitchens |
365 | | - if (type == None): |
366 | | - print "lacking parameters, function getAllBookingInfo exited :(" |
367 | | - return False |
368 | | - else: |
369 | | - allBookingInfo = [] |
370 | | - for room in kitchens: |
371 | | - allBookingInfo.append(getBookingInfo(room['roomId'])) |
372 | | - return allBookingInfo |
373 | | -
|
374 | | -''' |
375 | | - |
376 | 320 | # function: book a room using the cookie got freshly |
377 | 321 |
|
378 | 322 | def bookRoom(users = None, roomId = None, beginDay = None, beginTime = None, endDay = None, endTime = None): |
|
0 commit comments