def login(): if request.method == "POST": data = dict((k,v[0]) for k,v in dict(request.form).items()) if not data.get('name',None) or not data.get('password',None): errmsg = "name and password not null" return json.dumps({'code':'1','errmsg':errmsg}) if not check_login_name(data['name']): errmsg = "user does not exist" return json.dumps({'code':'1','errmsg':errmsg}) if data['password'] != get_user_name(data['name'])['password']: errmsg = "password error!" return json.dumps({'code':'1','errmsg':errmsg}) if get_user_name(data['name'])['status'] == 0: errmsg = "Your account has been locked" return json.dumps({'code':'1','errmsg':errmsg}) else: date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) update_user_lasttime(date,data['name']) session['name'] = data['name'] session['role'] = get_user_name(data['name'])['role'] session['status'] = get_user_name(data['name'])['status'] role = session.get('role',None) names = session.get('name',None) status = session.get('status',None) return json.dumps({'code':'0','errmsg':"login sucess",'roles':role,'name':names,'statu':status}) else: return render_template('login.html')
def user(): if not session.get('name', None) or session.get('role', None) != 'user': return redirect('/login') names = session.get('name', None) roles = session.get('role', None) return render_template('user.html', user=get_user_name(names), name=names, role=roles)
def home(): if 'username' in session: name=db.get_user_name(session['username']) return render_template("cinema.html",myUserName=name,myPhoneNumber=session['username']) else: resp = twilio.twiml.Response() resp.message("Hello, Mobile Monkey") return render_template("homepage.html")
def enter_schedule(): messages = db.get_unread_message_for_bot() pattern = "誰がいる" print(messages) for message in messages: print(message) match = re.search(pattern, message[0]) if match: lab_member = db.get_in_lab_member() # send_massage([db.get_user_name(message[1])],"文法エラーです") send_massage([db.get_user_name(message[1])], lab_member) else: s = syntax_matching(message[0]) print(s) if s == False: send_massage([db.get_user_name(message[1])], "文法エラーです") return else: send_massage([db.get_user_name(message[1])], message[0] + "します") #print(s) if s.span is None: s.span = "" s.show_all() month, week, s_flag = span_flag(s.span) d_list, me_list, wn_list = calc_startday(s_flag, s.days) member = select_member(s.grade) is_in_lab = select_is_in_lab(s.in_lab) if d_list != False: print(d_list) t = calc_time(s.time) if t != False: print(t) input_datetime_list = [datetime.combine(d, t) for d in d_list] for (i, me, wn) in zip(input_datetime_list, me_list, wn_list): i_str = i.strftime('%Y/%m/%d-%H:%M:%S') db.insert_reminder(s.item, month, me, week, wn, i_str, member, is_in_lab, 1)
def close(user_id): name = db.get_user_name(user_id)[0] text = texts.bye_named.format(name) helper.simple_print(text) sys.exit()
def on_message(self, message): #メーッセージ受信およびブロードキャスト global to_user global group_flag global waiters message = json.loads(message) print("on_message") print(message) print(self.get_current_user()) if (group_flag == False): db.insert_message( db.get_user_id_from_name(message["to_user"]), db.get_user_id_from_name(self.get_current_user()), db.get_now_time(), message['message'], 0) #self.messages.append(message) else: db.insert_message( db.get_group_id_from_name(message["to_user"]), db.get_user_id_from_name(self.get_current_user()), db.get_now_time(), message['message'], 0) print(to_user) print(group_flag) print(waiters) for waiter in waiters: print(waiter) if group_flag == False: print(db.get_user_id_from_name(to_user)) if self.check_active_time(message["to_user"], message): if waiter[1] != db.get_user_id_from_name( message["to_user"]): continue else: waiter[0].write_message({ 'img_path': message['img_path'], 'message': message['message'], 'to_user': message["to_user"], 'from_user': self.get_current_user(), 'my_name': self.get_current_user(), 'is_group': 'False' }) else: break else: group_user_list = db.get_group_user_list( db.get_group_id_from_name(message["to_user"])) for number in group_user_list: if waiter[1] == number: if waiter[0] == self: continue waiter[0].write_message({ 'img_path': message['img_path'], 'message': message['message'], 'to_user': message["to_user"], 'from_user': self.get_current_user(), 'my_name': db.get_user_name(number), 'is_group': 'True' }) print("send:" + waiter[1] + '\nmessage:' + message['message'])
def open(self, *args, **kwargs): #初期メッセージ送信 global to_user global group_flag global waiters name = self.get_current_user() user_id = db.get_user_id_from_name(name) connector = sqlite3.connect("Chat.db") cursur = connector.cursor() #ユーザがログインした時,そのユーザのIDを1にする sql = 'update User SET Is_in_Lab = 1 where User_ID = ' + user_id print("sql:" + sql) # print("login2_id:" + user_id) connector.execute(sql) connector.commit() cursur.close() connector.close() print("\n\n\n\n\n\n\n\nonope n\n\n\n\n\n\n\n\n\n\n\n") print("open") print(self) waiters.append( [self, db.get_user_id_from_name(self.get_current_user())]) self.messages = [] if (group_flag == False): for message in db.get_message( db.get_user_id_from_name(to_user), db.get_user_id_from_name(self.get_current_user())): #print(message) self.messages.append({ 'img_path': '/static/images/' + db.get_user_name(message[2]) + '.gif', 'message': message[4], 'to_user': db.get_user_name(message[1]), 'from_user': db.get_user_name(message[2]), 'my_name': self.get_current_user(), 'is_group': 'False' }) self.write_message({'messages': self.messages}) else: for message in db.get_group_message( db.get_group_id_from_name(to_user)): #print(message) self.messages.append({ 'img_path': '/static/images/' + db.get_user_name(message[2]) + '.gif', 'message': message[4], 'to_user': db.get_group_name(message[1]), 'from_user': db.get_user_name(message[2]), 'my_name': self.get_current_user(), 'is_group': 'True' }) self.write_message({'messages': self.messages})
def get_users_name(db, user_id): usersname = db.get_user_name(user_id) return usersname
def hello(): if 'username' in session: name=db.get_user_name(session['username']) return render_template("cinema.html",myUserName=name,myPhoneNumber=session['username']) else: return render_template("cinema.html",myUserName='******',myPhoneNumber='11111')
# in_labの指定があれば if (result[8] == 1): tmp = [] for member in members: if (db.get_is_in_lab(str(member))[0][0] == 1): tmp.append(member) members = tmp print(members) # メッセージ送信 user_name_list = [] for member in members: db.insert_message( member, BOT_ID, datetime.now().strftime('%Y/%m/%d-%H:%M:%S'), result[1], 0) user_name_list.append(db.get_user_name(member)) send_massage(user_name_list, result[1]) db.change_flag(result[0], 0) else: if (result[9] == 0): db.change_flag(result[0], 1) # print("failed1") # print (datetime.now().weekday()) #send_massage(["konishi","tanaka","shirasawa"],"ボットの自動送信機能のテストです") time.sleep(1)