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 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