Ejemplo n.º 1
0
 def get_user_info(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     user_info_dict = dict()
     sql_stm = "select user_name,user_nick_name,user_signature,user_gender_id,user_birthday," \
               "user_telephone,user_email,user_introduce,user_head,user_age,user_vocation," \
               "user_nation_id,user_province_id,user_city_id,user_register_time " \
               "from user_info where user_id={}".format(in_user_id)
     result = db.get_res(sql_stm)
     if result:
         user_info_dict['name'] = result[0][0]  # 用户名
         user_info_dict['nick_name'] = result[0][1]  # 用户昵称
         user_info_dict['signature'] = result[0][2]  # 用户签名
         user_info_dict['gender_id'] = result[0][3]  # 用户性别,1为男,2为女,3为保密
         if result[0][4] is None:
             user_info_dict['birthday'] = ''
             user_info_dict['age'] = 0
         else:
             user_info_dict['birthday'] = str(result[0][4])  # 用户生日
             user_info_dict['age'] = localtime(time())[0] - int(
                 str(result[0][4]).split('-')[0])  # 用户年龄
         user_info_dict['telephone'] = result[0][5]  # 设置用户登录手机号,非空
         user_info_dict['email'] = result[0][6]  # 设置登录邮箱,非空
         # self.introduce = result[0][7]  # 用户介绍bbb
         # self.head = result[0][8]  # 用户头像
         user_info_dict['vocation'] = result[0][10]  # 用户的职业信息
         # self.nation_id = result[0][11]  # 用户所属国家
         # self.province_id = result[0][12]  # 用户所属省
         # self.city_id = result[0][13]  # 用户所属城市
         user_info_dict['register_time'] = str(
             result[0][14].date())  # 用户注册时间,非空
     return str(user_info_dict)
Ejemplo n.º 2
0
    def set_user_info(cls, in_user_id, user_info_dict):
        nick_name = user_info_dict['nick_name']  # 用户昵称
        signature = user_info_dict['signature']  # 用户签名
        gender_id = user_info_dict['gender_id']  # 用户性别,1为男,2为女,3为保密
        birthday = user_info_dict['birthday']  # 用户生日
        if birthday != '':
            age = user_info_dict['age'] = localtime(time())[0] - int(
                birthday.split('-')[0])  # 用户年龄
            birthday = "'{}'".format(birthday)
        else:
            age = 0
            birthday = 'null'
        telephone = user_info_dict['telephone']  # 设置用户登录手机号,非空
        email = user_info_dict['email']  # 设置登录邮箱,非空
        vocation = user_info_dict['vocation']  # 用户的职业信息

        db = DBUtil()  # 创建数据库对象
        db.connect_db()  # 创建连接对象
        db.cur_db()  # 创建游标
        sql_stm = "update user_info set user_nick_name='{}',user_signature='{}',user_gender_id={}," \
                  "user_birthday={},user_telephone='{}',user_email='{}'," \
                  "user_age={},user_vocation='{}' " \
                  "where user_id={}".format(nick_name, signature, gender_id, birthday, telephone, email,
                                                age, vocation, in_user_id)
        result = db.exc_sql(sql_stm)
        return result
Ejemplo n.º 3
0
 def del_group(self):
     db = DBUtil()
     db.connect_db()
     db.cur_db()
     sql_stm = "delete from group_info where group_admin_id={} and group_name='{}'"\
         .format(self.admin_id, self.group_name)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 4
0
 def set_friend_policy(self, friendship_policy_id):
     self.friendship_policy_id = friendship_policy_id
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "update user_info set user_friendship_policy_id={} " \
               "where user_name='{}'".format(self.friendship_policy_id, self.name)
     return db.exc_sql(sql_stm)
Ejemplo n.º 5
0
 def set_status(self, status_id):
     self.status_id = status_id
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "update user_info set user_status_id={} " \
               "where user_name='{}'".format(self.status_id, self.name)
     return db.exc_sql(sql_stm)
Ejemplo n.º 6
0
 def rename_group(self, new_group_name):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "update friend_group set friend_group_name='{}' where friend_group_user_id={}"\
         .format(new_group_name, self.group_user_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 7
0
 def del_friend_group(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "delete from friend_group where friend_group_name='{}' and friend_group_user_id={}"\
         .format(self.group_name, self.group_user_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 8
0
 def add_friend_group(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "insert into friend_group(friend_group_name,friend_group_user_id) " \
               "values('{}',{})".format(self.group_name, self.group_user_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 9
0
 def set_group(self, group_id):
     self.friend_group = group_id
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "update friendship_info set friendship_friend_group_id={} where friendship_user_id={} and " \
               "friendship_friend_id={}".format(self.friend_group, self.user_id, self.friend_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 10
0
 def get_remark_name(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friendship_name from friendship_info where friendship_user_id={} and " \
               "friendship_friend_id={}".format(self.user_id, self.friend_id)
     result = db.get_res(sql_stm)
     self.remark_name = result[0][0]
     return self.remark_name
Ejemplo n.º 11
0
 def update_password(self, old_password, new_password):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     args = (encrypted_password(new_password), self.name,
             encrypted_password(old_password))
     sql_stm = "update user_info set user_password=%s where (user_name=%s and user_password=%s)"
     result = db.exc_sql(sql_stm, *args)
     return result
Ejemplo n.º 12
0
 def set_remark_name(self, remark_name):
     self.remark_name = remark_name
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "update friendship_info set friendship_name='{}' where friendship_user_id={} and " \
               "friendship_friend_id={}".format(self.remark_name, self.user_id, self.friend_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 13
0
 def get_status(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select user_status_id from user_info " \
               "where user_name='{}'".format(self.name)
     result = db.get_res(sql_stm)
     if result:
         self.status_id = result[0][0]
     return self.status_id
Ejemplo n.º 14
0
 def add_self_to_group(self):
     db = DBUtil()
     db.connect_db()
     db.cur_db()
     group_info = self.get_group_info(self.group_name)
     group_id = eval(group_info)[0]
     sql_stm = "insert into group_to_user(group_user_id,group_group_id) values({},{})"\
         .format(self.admin_id, group_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 15
0
 def del_friend(self):
     if self.friend_id is None or self.friend_id == self.user_id:
         return False
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "delete from friendship_info where (friendship_user_id={} and friendship_friend_id={}) or "\
               "(friendship_user_id={} and friendship_friend_id={})"\
         .format(self.user_id, self.friend_id, self.friend_id, self.user_id)
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 16
0
 def get_group_info(cls, group_name):
     db = DBUtil()
     db.connect_db()
     db.cur_db()
     sql_stm = "select group_id,group_admin_id,group_name from group_info where group_name='{}'".format(
         group_name)
     result = db.get_res(sql_stm)
     if result:
         return result[0].__str__()
     else:
         return ""
Ejemplo n.º 17
0
 def get_friend_id_list(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friendship_friend_id from friendship_info where friendship_user_id={}".format(
         in_user_id)
     result = db.get_res(sql_stm)
     friend_id_list = []
     for friend_id in result:
         friend_id_list.append(friend_id[0])
     return str(friend_id_list)
Ejemplo n.º 18
0
 def get_friend_group_name(cls, in_group_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friend_group_name from friend_group where friend_group_id={}".format(
         in_group_id)
     result = db.get_res(sql_stm)
     if result:
         return result[0][0]
     else:
         return None
Ejemplo n.º 19
0
 def get_init_group_id(friend_group_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friend_group_id from friend_group where friend_group_name='{}' " \
               "and friend_group_user_id={}".format("我的好友", friend_group_user_id)
     result = db.get_res(sql_stm)
     if result:
         return result[0][0]
     else:
         return "null"
Ejemplo n.º 20
0
 def get_all_group(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friend_group_name from friend_group where friend_group_user_id={}".format(
         in_user_id)
     result = db.get_res(sql_stm)
     group_list = []
     for group in result:
         group_list.append(group[0])
     return group_list
Ejemplo n.º 21
0
 def find_id(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select user_id from user_info where user_name='{}'".format(
         self.friend_name)
     result = db.get_res(sql_stm)
     if result:
         return result[0][0]
     else:
         return None
Ejemplo n.º 22
0
 def get_user_id(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     args = (self.name, )
     sql_stm = "select user_id from user_info where user_name=%s"
     result = db.get_res(sql_stm, *args)
     if result:
         self.id = result[0][0]
     else:
         self.id = None
     return self.id
Ejemplo n.º 23
0
 def id_to_name(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select user_name from user_info where user_id={}".format(
         in_user_id)
     result = db.get_res(sql_stm)
     if result:
         out_user_name = result[0][0]
     else:
         out_user_name = None
     return out_user_name
Ejemplo n.º 24
0
 def get_friend_group_id(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friend_group_id from friend_group where friend_group_user_id={}".format(
         self.group_user_id)
     result = db.get_res(sql_stm)
     if result:
         self.group_user_id = result[0][0]
     else:
         self.group_user_id = None
     return self.group_user_id
Ejemplo n.º 25
0
 def get_friend_list(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friendship_friend_id,friendship_name from friendship_info " \
               "where friendship_user_id={}".format(in_user_id)
     result = db.get_res(sql_stm)
     friend_list = []
     for friend in result:
         friend_mark_name = User.id_to_name(friend[0])
         friend_list.append((friend[0], friend_mark_name, friend[1]))
     return str(friend_list)
Ejemplo n.º 26
0
 def get_group(self):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friendship_friend_group_id from friendship_info where friendship_user_id={} and " \
               "friendship_friend_id={}".format(self.user_id, self.friend_id)
     result = db.get_res(sql_stm)
     if result:
         self.friend_group = result[0][0]
     else:
         self.friend_group = "null"
     return self.friend_group
Ejemplo n.º 27
0
 def name_to_id(cls, in_user_name):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     args = (in_user_name, in_user_name, in_user_name)  # 设置SQL语句参数
     sql_stm = "select user_id from user_info where " \
               "(user_name=%s or user_email=%s or user_telephone=%s)"
     result = db.get_res(sql_stm, *args)
     if result:
         out_user_id = result[0][0]
     else:
         out_user_id = None
     return out_user_id
Ejemplo n.º 28
0
 def add_friend(self):
     if self.friend_id is None or self.friend_id == self.user_id:
         return False
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "insert into friendship_info(friendship_user_id,friendship_friend_id," \
               "friendship_name,friendship_friend_type_id,friendship_friend_group_id) " \
               "values({},{},'{}',{},{}),({},{},'',1,{})"\
         .format(self.user_id, self.friend_id, self.remark_name, self.friend_type, self.friend_group,
                 self.friend_id, self.user_id, self.get_init_group_id(self.friend_id))
     result = db.exc_sql(sql_stm)
     return result
Ejemplo n.º 29
0
 def create_group(self):
     db = DBUtil()
     db.connect_db()
     db.cur_db()
     sql_stm = "insert into group_info(group_admin_id,group_name) values({},'{}')"\
         .format(self.admin_id, self.group_name)
     result1 = db.exc_sql(sql_stm)
     if result1:
         result2 = self.add_self_to_group()
         if result2:
             return True
         else:
             return False
     return False
Ejemplo n.º 30
0
 def get_all_friend(cls, in_user_id):
     db = DBUtil()  # 创建数据库对象
     db.connect_db()  # 创建连接对象
     db.cur_db()  # 创建游标
     sql_stm = "select friendship_friend_id,friendship_friend_group_id from friendship_info " \
               "where friendship_user_id={}".format(in_user_id)
     result = db.get_res(sql_stm)
     friend_dict = {}
     for friend in result:
         friend_group_name = FriendGroup.get_friend_group_name(friend[1])
         friend_name = User.id_to_name(friend[0])
         if friend_group_name not in friend_dict:
             friend_dict[friend_group_name] = []
         friend_dict[friend_group_name].append(friend_name)
     return friend_dict.__str__()