def show_member(self, user_id, group_ID): sql = Mysql() info = [] try: result = sql.select("*", "ismember", "group_ID", group_ID) for row in result: record = {} id1 = row[0] print(id1) record["ID"] = id1 result1 = sql.multiple_select("*", "isfriend", "use_user_ID", user_id, "user_ID", id1) if result1: record["isfriend"] = "1" else: record["isfriend"] = "0" record["icon"] = ord(id1[-1]) % 3 result2 = sql.select("*", "users", "user_ID", id1) for row1 in result2: record["name"] = row1[0] info.append(record) sql.disconnect() print("success!\n") return info except IOError: return None except ValueError: return None
def initialize_request(self, user_id, group_id): sql = Mysql() info = [] time1 = tm.time() time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') info.append(user_id) info.append(group_id) result = sql.multiple_select("*", "ismember", "group_ID", group_id, "user_ID", user_id) if result: info.append("is_mem") else: info.append("no_mem") try: # should use mysql, but just profile_file here... if info[2] == "is_mem": info.append("already_in") info.append(str(int(time1))) info.append(time) else: info.append("ready_to_apply") info.append(str(int(time1))) info.append(time) sql.insert_requirement("wanttojoin", info) print("success!\n") sql.disconnect() return except IOError: return None except ValueError: return None
def update_request(self, user_id, group_id, time): sql = Mysql() record = {} try: result = sql.multiple_select("status, status2", "wanttojoin", "group_ID", group_id, "user_ID", user_id) for row in result: if row[0] == "already_in": print("alright") elif row[1] == "ready_to_apply": sql.update("wanttojoin", "status2", "send_request", "group_ID", group_id, "user_ID", user_id) sql.update("wanttojoin", "time", time, "group_ID", group_id, "user_ID", user_id) elif row[1] == "send_request": sql.update("wanttojoin", "status2", "ready_to_apply", "group_ID", group_id, "user_ID", user_id) sql.update("wanttojoin", "time", time, "group_ID", group_id, "user_ID", user_id) result = sql.multiple_select("*", "wanttojoin", "group_ID", group_id, "user_ID", user_id) for row in result: record["name"] = row[1] record["description"] = row[0] + " want to join it!" if row[2] == "is_mem": record["status"] = "0" elif row[3] == "ready_to_apply": record["status"] = "2" elif row[3] == "send_request": record["status"] = "1" return record except IOError: return None except ValueError: return None
def check_relation(self, user_id, friend_id): sql = Mysql() try: result = sql.multiple_select("*", "isfriend", "use_user_ID", user_id, "user_ID", friend_id) sql.disconnect() if result: print("ignore") else: self.insert_friend(user_id, friend_id) return except IOError: return None except ValueError: return None
def check_request(self, user_id, group_id): sql = Mysql() info = [] try: # should use mysql, but just profile_file here... result = sql.multiple_select("*", "wanttojoin", "group_ID", group_id, "user_ID", user_id) sql.disconnect() if result: return True else: self.initialize_request(user_id, group_id) return except IOError: return None except ValueError: return None