def roomStatus(self): if not public.keyExists('flush'): print('flush') public.setRedis('flush', True, expire=8, forever=False) self.flush() if public.keyExists('roomStatus'): return eval(public.getRedis('roomStatus')) else: return {}
def bannerColor(self): if public.keyExists('isRed'): if self.isRed: return { 'front': '#ffffff', 'back': '#F17C67' } else: return { 'front': '#ffffff', 'back': '#17abe3' } else: return { 'front': '#ffffff', 'back': '#17abe3' }
def mon(self): if public.keyExists('mon'): return eval(public.getRedis('mon')) else: return True
def today(self): if public.keyExists('today'): return eval(public.getRedis('today')) else: return True
def tomorrow(self): if public.keyExists('tomorrow'): return eval(public.getRedis('tomorrow')) else: return True
def isRed(self): if public.keyExists('isRed'): return eval(public.getRedis('isRed')) else: return True
def title(self): if public.keyExists('title'): return str(public.getRedis('title'), encoding="utf-8") else: return '座位助手'
def message(self): if public.keyExists('close_mess'): return str(public.getRedis('close_mess'), encoding = "utf-8") else: return '此功能暂时关闭'
def detect(self): if public.keyExists('detect'): return eval(public.getRedis('detect')) else: return True
def _users(self): if public.keyExists('users'): return eval(public.getRedis('users')) else: return {}
def _usersOnRunning(self): if public.keyExists('_usersOnRunning'): return eval(public.getRedis('_usersOnRunning')) else: return {}
def deleteUser(self, studentNum, success=False, booked=False): if type(studentNum) is not str: raise TypeError users = self._users usersOnRunning = self._usersOnRunning roomStatus = self.roomStatus user = users[studentNum] try: usersOnRunning.pop(studentNum) except KeyError: running = False else: running = True self._usersOnRunning = usersOnRunning count = 0 if running: if public.keyExists('d-' + studentNum): count = public.getRedis('d-' + studentNum) else: count = 0 public.deleteRedis('d-' + studentNum) for roomId in user['roomIds']: try: roomStatus[str(roomId)].remove(studentNum) except KeyError: return False except ValueError: pass else: self.roomStatus = roomStatus try: users.pop(studentNum) except KeyError: return False else: self._users = users if success: public.incrRedis('detect_num') u = User(studentNum) booked = u.bookedSeat try: mess = booked['message'].split(',') room = mess[0] seatNum = mess[1][3:] except Exception: room = booked seatNum = '-' data = { "keyword1": { "value": room }, "keyword2": { "value": booked['time'] }, "keyword3": { "value": seatNum, "color": "#FF6666" }, "keyword4": { "value": int(count) }, } code = public.pushMessage( access_token=self.wechat_client.access_token, openid=u.openid, form_id=user['formId'], data=data, method='detect') return code if booked: u = User(studentNum) data = { "keyword1": { "value": '已有预约', "color": "#FF6666" }, "keyword2": { "value": '您可能已具有一个预约,请登录小程序查看。若无预约,请到用户群报告异常。' } } code = public.pushMessage( access_token=self.wechat_client.access_token, openid=u.openid, form_id=user['formId'], data=data, method='delete_mon') print(code) return code return True
print(code) self._users = {} self.roomStatus = {} self._usersOnRunning = {} if __name__ == "__main__": m = Monitor() expire = datetime.datetime.combine(datetime.date.today(), datetime.time(23, 50, 0)) start = datetime.datetime.combine(datetime.date.today(), datetime.time(11, 50, 0)) # m.flush() # m.addUser("2014301220099", [8,9,10,11], expireTime=expire, start='840', end='1320', buildingId='1',formId='0',stop='13:00', enableTime=start) # m.activeUser('2014301220099') # m.deleteUser('2014301220099',False) # m.addUser("2014301220011", [11, 17], expireTime=expire) # public.setRedis('flush', True, expire=10, forever=False) print(public.keyExists('flush')) print(m._users) print(m.roomStatus) print(m._usersOnRunning) # m.roomStatus = {} # m._usersOnRunning = {} # print(m.deleteUser('2014301220099')) # for room in m.roomStatus.keys(): # print(room) # users = m.roomStatus[room] # print(users)
def __init__(self): self.monitor = Monitor() if public.keyExists('error'): self.monitor.deleteMon() public.setRedis('error', True, expire=100, forever=False) self.sleeping = 2