def get_personal_page_extension_by_user_id(user_id, base_url):
        """通过user_id 获取到额外的信息(个人主页的信息)"""
        user = User()
        user_accuracy_extension_instance = DBOHHOUserAccuracyExtension()
        user_extension = user_accuracy_extension_instance.get_by_user_id_only_one(
            user_id)
        data = dict()
        if user_extension:
            data = user_accuracy_extension_instance.get_information(
                user_extension, base_url)
            if user_extension.occupation_id:
                data["occupation_name"] = user_extension.occupation.name
            else:
                data["occupation_name"] = ""

            if user_extension.position_id:
                data["position_name"] = user_extension.position.name
            else:
                data["position_name"] = ""
            if user_extension.degree_id:
                data["degree_name"] = user_extension.degree.name
            else:
                data["degree_name"] = ""

            if user_extension.birthday:
                data["age"] = user.get_age(user_extension.birthday)
                data["zodiac"] = user.get_zodiac(user_extension.birthday)

        OHHOLog.print_log("user_accuracy_extension_data")
        OHHOLog.print_log(data)

        return data
Пример #2
0
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition(
        )
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

        self.user_favourite_book = DBOHHOUserFavouriteBook()
        self.user_favourite_movie = DBOHHOUserFavouriteMovie()
        self.user_favourite_sport = DBOHHOUserFavouriteSport()
        self.user_favourite_music = DBOHHOUserFavouriteMusic()
        self.user_icon = DBOHHOUserIcon()
        self.user_description = DBOHHOUserDescription()
        self.user_impression = DBOHHOUserImpression()
    def get_accuracy_extension_by_user_id(user_id, base_url):
        """通过user_id 获取到额外的信息"""
        user_accuracy_extension_instance = DBOHHOUserAccuracyExtension()
        user_extension = user_accuracy_extension_instance.get_by_user_id_only_one(
            user_id)
        data = dict()
        if user_extension:
            # for user_extension in user_accuracy_extension_list:
            data = user_accuracy_extension_instance.get_information(
                user_extension, base_url)
            if user_extension.occupation_id:
                data["occupation_name"] = user_extension.occupation.name
            else:
                data["occupation_name"] = ""

            if user_extension.position_id:
                data["position_name"] = user_extension.position.name
            else:
                data["position_name"] = ""
            if user_extension.degree_id:
                data["degree_name"] = user_extension.degree.name
            else:
                data["degree_name"] = ""

        OHHOLog.print_log("user_accuracy_extension_data")
        OHHOLog.print_log(data)

        return data
Пример #4
0
    def post(self):
        the_post = Post()
        user_id = the_post.get_user_id(self)
        submit = the_post.get_submit(self)
        delete_or_restore = the_post.get_delete_or_restore(self)

        instance = User()
        user = instance.get_by_id(user_id)

        delete_url = MANAGEMENT_USER_DELETE_URL + "?user_id=" + str(user_id)
        if delete_or_restore and user:
            if user.state:
                success = instance.delete(user)
            else:
                success = instance.restore(user)
            if success:
                return self.redirect(MANAGEMENT_USER_LIST_URL)
            else:
                return self.redirect(delete_url)
        if submit:
            user_extension = the_post.get_user_extension(self)
            user_extension_instance = DBOHHOUserAccuracyExtension()
            user_extension_object = user_extension_instance.get_by_user(
                user_id)
            success = user_extension_instance.update(user_extension_object,
                                                     user_extension)
            if success:
                return self.redirect(MANAGEMENT_USER_LIST_URL)
            else:
                return self.redirect(delete_url)
        return self.redirect(delete_url)
Пример #5
0
 def __init__(self, index=0):
     self.user = DBOHHOUser(index)
     self.user_accuracy_extension = DBOHHOUserAccuracyExtension(index)
     self.user_description = DBOHHOUserDescription(index)
     self.user_favourite_book = DBOHHOUserFavouriteBook(index)
     self.user_favourite_movie = DBOHHOUserFavouriteMovie(index)
     self.user_favourite_music = DBOHHOUserFavouriteMusic(index)
     self.user_favourite_sport = DBOHHOUserFavouriteSport(index)
     self.user_icon = DBOHHOUserIcon(index)
     self.user_impression = DBOHHOUserImpression(index)
Пример #6
0
class EncounterStrategy(object):
    def __init__(self, user_id):
        self.user_id = user_id
        self.user = User()
        self.map = DBOHHOMapInformation()
        self.impression = DBOHHOUserImpression()
        self.extension = DBOHHOUserAccuracyExtension()

    def get_impression(self):
        return self.impression.get_user_impression_list_by_user_id(
            self.user_id)

    def get_sex(self):
        extension = self.extension.get_by_user(self.user_id)
        if extension and extension.sex:
            return '男孩纸' if extension.sex == 1 else '女孩纸'
        return "X孩纸"

    def get_age(self):
        extension = self.extension.get_by_user(self.user_id)
        if extension and extension.birthday:
            return self.user.get_age_display(extension.birthday)
        return "XX后"

    def get_occupation(self):
        extension = self.extension.get_by_user(self.user_id)
        if extension and extension.occupation:
            return extension.occupation.name
        return "XX"

    def get_position(self):
        extension = self.extension.get_by_user(self.user_id)
        if extension and extension.position:
            return extension.position.name
        return "XX"

    def get_character(self):
        pass

    def get_favourite(self):
        pass

    def get_near_pois(self, longitude, latitude):
        pass

    def get_default(self):
        pass

    def get_end_words(self):
        pass
 def add_user_exclude(user_id, exclude_user_ids):
     extension = DBOHHOUserAccuracyExtension()
     user = extension.get_by_user(user_id)
     if user:
         success = extension.update(user, {"exclude": exclude_user_ids})
         if success:
             return Result.result_success("update successfully!")
         else:
             return Result.result_failed("update failed!")
     else:
         success = extension.add({
             "user_id": user_id,
             "exclude": exclude_user_ids
         })
         if success:
             return Result.result_success("add successfully!")
         else:
             return Result.result_failed("add failed!")
Пример #8
0
 def __init__(self):
     self.device = Device()
     self.user = User()
     self.meet = Meet()
     self.friend = Friend()
     self.map = DBOHHOMapInformation()
     self.match_condition = LogicGetMatchCondition()
     self.condition = MatchCondition()
     self.condition_relation = UserAndMatchCondition()
     self.device_relation = DBOHHOUserAndDeviceRelation()
     self.user_extension = DBOHHOUserAccuracyExtension()
     self.exclude = DBOHHORecordExclude()
     self.configuration = DBOHHOUserConfiguration()
     self.match_apply = DBOHHORecordMatchApply()
     self.favourite_book = DBOHHOUserFavouriteBook()
     self.favourite_movie = DBOHHOUserFavouriteMovie()
     self.favourite_music = DBOHHOUserFavouriteMusic()
     self.favourite_sport = DBOHHOUserFavouriteSport()
     self.match_online = DBOHHOMatchOnline()
Пример #9
0
 def __init__(self):
     self.user = DBOHHOUser()
     self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
     self.password = Password()
     self.token = Token()
     self.user_extension = DBOHHOUserAccuracyExtension()
     self.interest = DBOHHOInterest()
     self.map = DBOHHOMapInformation()
     self.device = DBOHHODevice()
     self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition()
     self.match_condition = DBOHHORecordMatchCondition()
     self.im_user = DBOHHOIMUser()
     self.im_user_relation = DBOHHOIMUserRelation()
     self.user_configuration = DBOHHOUserConfiguration()
     self.imei = IMEI()
     self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
     self.friend = Friend()
     self.apply = DBOHHORecordMatchApply()
     self.country_code = DBOHHOCountryCode()
Пример #10
0
 def delete_one_user_exclude(user_id, exclude_user_id):
     extension = DBOHHOUserAccuracyExtension()
     user = extension.get_by_user(user_id)
     if user:
         exclude = user.exclude
         exclude_user_id_list = exclude.split(",")
         exclude_user_id_list = [int(e) for e in exclude_user_id_list]
         if int(exclude_user_id) in exclude_user_id_list:
             exclude_user_id_list.remove(exclude_user_id)
             exclude_string = ",".join(exclude_user_id_list)
             success = extension.update(user, {"exclude": exclude_string})
             if success:
                 return Result.result_success("update successfully!")
             else:
                 return Result.result_failed("update failed!")
         else:
             return Result.result_success("no such user in your exclude!")
     else:
         return Result.result_failed("no such user extension!")
Пример #11
0
class LogicMatch(object):
    def __init__(self):
        self.device = Device()
        self.user = User()
        self.meet = Meet()
        self.friend = Friend()
        self.map = DBOHHOMapInformation()
        self.match_condition = LogicGetMatchCondition()
        self.condition = MatchCondition()
        self.condition_relation = UserAndMatchCondition()
        self.device_relation = DBOHHOUserAndDeviceRelation()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.exclude = DBOHHORecordExclude()
        self.configuration = DBOHHOUserConfiguration()
        self.match_apply = DBOHHORecordMatchApply()
        self.favourite_book = DBOHHOUserFavouriteBook()
        self.favourite_movie = DBOHHOUserFavouriteMovie()
        self.favourite_music = DBOHHOUserFavouriteMusic()
        self.favourite_sport = DBOHHOUserFavouriteSport()
        self.match_online = DBOHHOMatchOnline()

    def get_exclude_user_list(self, user_id):
        created_at = OHHODatetime.get_today_start()
        created_at = OHHODatetime.beijing2utc(created_at)
        one_day_before = OHHODatetime.get_some_hour_after(created_at, -24)
        query = self.exclude.get_query()
        query = self.exclude.get_great_than_equal_created_at(
            query, one_day_before)
        query1 = self.exclude.get_by_user(query, user_id)
        query2 = self.exclude.get_by_exclude_user(query, user_id)
        if self.exclude.is_empty(query1):
            user1_list = list()
        else:
            user1_list = [exclude.exclude_user_id for exclude in query1]

        if self.exclude.is_empty(query1):
            user2_list = list()
        else:
            user2_list = [exclude.user_id for exclude in query2]
        return list(set(user1_list + user2_list))

    def get_exclude_user_list_up224hour(self, user_id):
        query = self.exclude.get_query()
        query1 = self.exclude.get_by_user(query, user_id)
        query2 = self.exclude.get_by_exclude_user(query, user_id)
        if self.exclude.is_empty(query1):
            user1_list = list()
        else:
            user1_list = [exclude.exclude_user_id for exclude in query1]

        if self.exclude.is_empty(query1):
            user2_list = list()
        else:
            user2_list = [exclude.user_id for exclude in query2]
        user_id_list = list(set(user1_list + user2_list))
        user_id_list_before24hour = self.get_exclude_user_list(user_id)
        return OHHOOperation.list_minus_list(user_id_list,
                                             user_id_list_before24hour)

    def get_user_ids_by_device_identities(self, device_ids):
        user_id_list = list()
        for identity in device_ids:
            self.device.set_identity(identity)
            device = self.device.device.get_by_identity()
            if device:
                relation = self.device.relation.get_by_device(device.id)
                if relation:
                    user_id_list.append(relation.user_id)
        return list(set(user_id_list))

    def get_condition(self, user_id, name):
        result, query = self.match_condition.get(user_id, name)
        return query

    def get_user_accuracy_extension(self, user_id_list):
        return self.user_extension.get_by_user_list(user_id_list)

    # **************************************************************** VERSION 2 *************************
    def clear_secondary_device(self, device_list):
        result = list()
        for d in device_list:
            d = d.strip()
            if d:
                self.device.set_identity(d)
                device = self.device.get_by_identity()
                if device:
                    relation = self.device_relation.get_by_device(device.id)
                    if relation and relation.type == 1:
                        result.append(d)
        return result

    def match_by_condition_version2(self, user_id, user_id_list):
        # 根据user_id获取配对条件
        # 根据user_id_list获取配对用户列表
        # 根据条件从用户列表中配对

        # result = user_id_list
        # return result

        result = list()
        condition = self.condition_relation.get_nearest_match_relation_by_user(
            user_id)
        if condition:
            match_condition = self.condition.get_by_id(
                condition.match_condition_id)
            if match_condition:
                query = self.user_extension.get_by_user_list(user_id_list)

                sex = match_condition.sex
                if sex and sex != 3:
                    query = self.user_extension.get_by_sex(query, sex)

                small_age = match_condition.small_age
                big_age = match_condition.big_age
                if small_age and big_age:
                    this_year = OHHODatetime.get_now().year
                    small_age_year = this_year - small_age
                    big_age_year = this_year - big_age

                    big_age_year_start = str(big_age_year) + "-1-1"
                    date_big_age_year_start = OHHODatetime.string2date(
                        big_age_year_start)
                    small_age_year_end = str(small_age_year) + "-1-1"
                    date_small_age_year_end = OHHODatetime.string2date(
                        small_age_year_end)
                    query = self.user_extension.find_by_birthday(
                        query, date_big_age_year_start,
                        date_small_age_year_end)
                if self.user_extension.is_empty(query):
                    pass
                else:
                    result = [ue.user_id for ue in query]
        return result

    def duplex_match(self, user_id, user_id_list):
        result = list()
        OHHOLog.print_log(user_id_list)
        user_id_list = self.match_by_condition_version2(user_id, user_id_list)
        for uid in user_id_list:
            temp = self.match_by_condition_version2(uid, [user_id])
            if temp:
                result.append(uid)
        return result

    #  compute start
    def compute_online_user(self, user_id_list):
        online_id_list = list()
        for user_id in user_id_list:
            if self.is_match_online(user_id):
                online_id_list.append(user_id)
        return online_id_list

    def compute_favourite_book(self, user_id, another_user_id):
        query = self.favourite_book.get_query()
        user_query = self.favourite_book.get_by_user(query, user_id)
        another_user_query = self.favourite_book.get_by_user(
            query, another_user_id)
        user_book_isbn = [book.isbn for book in user_query]
        another_user_isbn = [book.isbn for book in another_user_query]
        result = list(
            OHHOOperation.set_intersect_set(set(user_book_isbn),
                                            set(another_user_isbn)))
        return result

    def compute_favourite_movie(self, user_id, another_user_id):
        query = self.favourite_movie.get_query()
        user_query = self.favourite_movie.get_by_user(query, user_id)
        another_user_query = self.favourite_movie.get_by_user(
            query, another_user_id)
        user_movie_id = [movie.movie_id for movie in user_query]
        another_user_movie_id = [
            movie.movie_id for movie in another_user_query
        ]
        result = list(
            OHHOOperation.set_intersect_set(set(user_movie_id),
                                            set(another_user_movie_id)))
        return result

    def compute_favourite_music(self, user_id, another_user_id):
        query = self.favourite_music.get_query()
        user_query = self.favourite_music.get_by_user(query, user_id)
        another_user_query = self.favourite_music.get_by_user(
            query, another_user_id)
        user_music_id = [music.music_id for music in user_query]
        another_user_music_id = [
            music.music_id for music in another_user_query
        ]
        result = list(
            OHHOOperation.set_intersect_set(set(user_music_id),
                                            set(another_user_music_id)))
        return result

    def compute_favourite_sport(self, user_id, another_user_id):
        query = self.favourite_sport.get_query()
        user_query = self.favourite_sport.get_by_user(query, user_id)
        another_user_query = self.favourite_sport.get_by_user(
            query, another_user_id)
        user_sport_id = [sport.sport_id for sport in user_query]
        another_user_sport_id = [
            sport.sport_id for sport in another_user_query
        ]
        result = list(
            OHHOOperation.set_intersect_set(set(user_sport_id),
                                            set(another_user_sport_id)))
        return result

    def compute_get_total_count(self, user_id, another_user_id):
        book = self.compute_favourite_book(user_id, another_user_id)
        movie = self.compute_favourite_movie(user_id, another_user_id)
        music = self.compute_favourite_music(user_id, another_user_id)
        sport = self.compute_favourite_sport(user_id, another_user_id)
        total_length = len(book) + len(movie) + len(music) + len(sport)
        return total_length, book, movie, music, sport

    def compute_main(self, user_id, user_id_list):
        result = 0
        current_length = 0
        online_user_list = self.compute_online_user(user_id_list)
        for another_user_id in online_user_list:
            temp_length, book, movie, music, sport = self.compute_get_total_count(
                user_id, another_user_id)
            if current_length < temp_length:
                current_length = temp_length
                result = another_user_id
        return result

    # compute end

    def is_in_meeting(self, user_id):
        # 获取见面中表的有效申请列表
        # 只有取消(两方自动结束)和结束时meeting才会结束(和实际的见面后结束有区别)
        return self.meet.get_apply_id_list_by_user_from_meeting(user_id)

    def has_duplex_agree(self, user_id, user_id_list, base_url):
        result = False
        redis_name = REDIS_DUPLEX_AGREE_PREFIX + str(user_id)
        duplex_agree_user_ids = RedisDB.list_get_all(redis_name)
        duplex_agree_user_ids = [
            RedisDB.to_bytes(data) for data in duplex_agree_user_ids
        ]
        for the_user_id in duplex_agree_user_ids:
            the_user_id = str(the_user_id)
            OHHOLog.print_log(the_user_id)
            some_user_id, apply_id = the_user_id.split(",")
            some_user_id = int(some_user_id)
            apply_id = int(apply_id)
            if some_user_id in user_id_list:
                state = self.meet.get_user_state_by_user(some_user_id)
                if not result and state == PUSH_STATE_TYPE_END_MEET:
                    information = self.user.get_push_user_information(
                        some_user_id, apply_id, base_url)
                    self.user.push_user_information(
                        user_id, PUSH_STATE_TYPE_AGREE_MEET, information)
                    information = self.user.get_push_user_information(
                        user_id, apply_id, base_url)
                    self.user.push_user_information(
                        some_user_id, PUSH_STATE_TYPE_AGREE_MEET, information)

                    # 添加两个人的状态为见面中
                    self.meet.add_meeting(apply_id, user_id)
                    self.meet.add_meeting(apply_id, the_user_id)

                    result = True
                else:
                    RedisDB.list_left_push(redis_name, the_user_id)
        return result

    def is_match_open(self, user_id):
        configuration = self.configuration.get_by_user(user_id)
        return configuration.is_match

    def clear_by_is_match(self, user_id_list):
        result = list()
        for user_id in user_id_list:
            if self.is_match_open(user_id):
                result.append(user_id)
        return result

    def add_apply(self, user_id, match_user_id):
        the_apply = self.meet.get_nearest_apply_by_user_and_another_user(
            user_id, match_user_id)
        the_reverse_apply = self.meet.get_nearest_apply_by_user_and_another_user(
            match_user_id, user_id)
        if the_apply or the_reverse_apply:
            is_time_valid = self.meet.is_valid_apply(the_apply)
            reverse_is_time_valid = self.meet.is_valid_apply(the_reverse_apply)
            if is_time_valid or reverse_is_time_valid:
                return None

        relation1 = self.condition_relation.get_nearest_match_relation_by_user(
            user_id)
        relation2 = self.condition_relation.get_nearest_match_relation_by_user(
            match_user_id)
        self.meet.add_apply(user_id, match_user_id,
                            relation1.match_condition_id,
                            relation2.match_condition_id)
        return self.meet.get_nearest_apply_by_user_and_another_user(
            user_id, match_user_id)

    def parse_intersection(self, intersection):
        result = list()
        for the_id in intersection:
            name = self.user.get_interest_name_by_id(the_id)
            if name:
                result.append(name)
        return result

    def push_information(self, to_user_id, user_id, apply_id, base_url):
        information = self.user.get_basic_user_information(user_id, base_url)
        information["apply_id"] = apply_id
        information["user_id"] = user_id
        return self.user.push_user_information(to_user_id,
                                               PUSH_STATE_TYPE_APPLY_MEET,
                                               information)

    # 清除见面但没有结束的人
    def clear_by_met_not_end(self, user_id_list):
        result = list()
        for user_id in user_id_list:
            state = self.meet.get_user_state_by_user(user_id)
            if state in (PUSH_STATE_TYPE_MEETING, PUSH_STATE_TYPE_SINGLE_MEET,
                         PUSH_STATE_TYPE_MET):
                continue
            result.append(user_id)
        return result

    def clear_by_meet_in24hour(self, user_id, user_id_list):
        meet_in24hour_user_ids = self.meet.get_meet_in24hour_user_ids(user_id)
        OHHOLog.print_log("meet in 24 hour")
        OHHOLog.print_log(meet_in24hour_user_ids)
        return OHHOOperation.list_minus_list(user_id_list,
                                             meet_in24hour_user_ids)

    def clear_by_friend(self, user_id, user_id_list):
        friends = self.friend.get_valid_by_account(user_id)
        friend_user_id_list = [f.friend_account_id for f in friends]
        return OHHOOperation.list_minus_list(user_id_list, friend_user_id_list)

    def sorted_by_rules(self, user_id, user_id_list):
        # 24小时内见过面的人
        # 24小时前被拒绝过的或拒绝过我的人
        user_id_not_meet = list()
        user_id_exclude = list()
        user_id_meet = list()
        meet_in24hour_user_ids = self.meet.get_meet_in24hour_user_ids(user_id)
        exclude_before24hour_user_ids = self.get_exclude_user_list_up224hour(
            user_id)
        for the_user_id in user_id_list:
            if the_user_id in meet_in24hour_user_ids:
                user_id_meet.append(the_user_id)
            elif the_user_id in exclude_before24hour_user_ids:
                user_id_exclude.append(the_user_id)
            else:
                user_id_not_meet.append(the_user_id)
        return user_id_not_meet + user_id_exclude + user_id_meet

    def has_valid_apply(self, user_id):
        valid_timestamp = self.match_apply.get_valid_timestamp()
        query = self.match_apply.get_query()
        query = self.match_apply.get_great_than_equal_timestamp(
            query, valid_timestamp)
        apply1 = self.match_apply.get_by_one_user(query, user_id)
        apply1 = self.match_apply.order_by_id_desc(apply1)
        apply1_first = self.match_apply.first(apply1)
        apply2 = self.match_apply.get_by_another_user(query, user_id)
        apply2 = self.match_apply.order_by_id_desc(apply2)
        apply2_first = self.match_apply.first(apply2)

        if apply1_first and apply2_first:
            the_apply = apply1_first if apply1_first.timestamp > apply2_first.timestamp else apply2_first
        elif apply1_first:
            the_apply = apply1_first
        else:
            the_apply = apply2_first

        return self.meet.is_the_apply_valid(
            the_apply), the_apply.id if the_apply else 0

    def clear_outdated_user(self):
        timestamp = OHHODatetime.get_current_timestamp()
        timestamp = timestamp - 1 * 60 * 1000
        query = self.match_online.get_query()
        delete_query = self.match_online.get_less_than_timestamp(
            query, timestamp)
        success = self.match_online.delete_some(delete_query)
        if success:
            OHHOLog.print_log(
                Result.result_success("clear online outdated user"))
        else:
            OHHOLog.print_log(
                Result.result_failed("clear online outdated user"))

    def update_match_online(self, user_id):
        timestamp = OHHODatetime.get_current_timestamp()
        instance = self.match_online.get_by_user(user_id)
        if instance:
            success = self.match_online.update(instance,
                                               {"timestamp": timestamp})
            if success:
                OHHOLog.print_log(
                    Result.result_success("update online for user %d" %
                                          (int(user_id))))
            else:
                OHHOLog.print_log(
                    Result.result_failed("update online for user %d" %
                                         (int(user_id))))
        else:
            success = self.match_online.add({"user_id": user_id})
            if success:
                OHHOLog.print_log(
                    Result.result_success("add online for user %d" %
                                          (int(user_id))))
            else:
                OHHOLog.print_log(
                    Result.result_failed("add online for user %d" %
                                         (int(user_id))))

    def is_match_online(self, user_id):
        instance = self.match_online.get_by_user(user_id)
        if instance:
            return True
        else:
            return False

    def has_nickname(self, user_id):
        user_extension = self.user_extension.get_by_user(user_id)
        if user_extension and user_extension.nickname:
            return True
        else:
            return False

    def match_version22(self,
                        user_id,
                        device_list_string,
                        base_url,
                        identity_id=None):
        # 查看本人是否打开了配对开关
        # 查看本人状态是否在见面中
        # 查看本人状态是否是有有效的配对
        # 清除不是交友设备的设备(type=1是交友设备)
        # 根据device_list得到用户id_list
        # 过滤掉今天匹配并不中意的人
        # 过滤掉未打开匹配开关的人
        # 过滤掉正在见面的人
        # 过滤掉已经见面但还没有结束的人
        # 过滤掉24小时内见过面的人
        # 过滤掉是好友的人
        # 根据性别和年龄区间筛选用户列表,根据条件找出符合条件的用户列表
        # 从符合条件的用户列表中依次根据用户ID获取配对条件, 根据配对条件看当前用户是否符合条件
        # 将第一个符合条件的用户添加到申请表中,并向两个人发送推送(推送对方的个人信息和推送的类型,这里是申请见面)
        user_id = int(user_id)
        self.clear_outdated_user()
        self.update_match_online(user_id)

        if not self.has_nickname(user_id):
            return Result.result_failed("please add nickname firstly!")

        if user_id and identity_id:
            OHHOLog.print_log(user_id)
            OHHOLog.print_log(identity_id)
            self.device.set_identity(identity_id)
            device = self.device.get_by_identity()
            if device:
                relations = self.device_relation.get_valid_by_device(device.id)
                the_relation = self.device_relation.first(relations)
                if the_relation and the_relation.user_id == user_id:
                    pass
                else:
                    information = "no device and user relation, you have no right to match!"
                    OHHOLog.print_log(information)
                    # return Result.result_failed(information)
            else:
                information = "no such device, you have no right to match!"
                OHHOLog.print_log(information)
                # return Result.result_failed(information)
        else:
            if user_id:
                information = "user %d is invalid, you have no right to match!" % user_id
                OHHOLog.print_log(information)
                # return Result.result_failed(information)
            else:
                information = "user or device is invalid, you have no right to match!"
                OHHOLog.print_log(information)
                # return Result.result_failed(information)

        is_match = self.is_match_open(user_id)
        if not is_match:
            OHHOLog.print_log("%d match switch closed!" % user_id)
            return Result.result_failed("please open match switch!")

        if self.is_in_meeting(user_id):
            OHHOLog.print_log("%d is in meeting" % user_id)
            return Result.result_failed("you are still in meeting!")
        OHHOLog.print_log("%d is not in meeting" % user_id)

        has_valid_apply, the_apply_id = self.has_valid_apply(user_id)
        if has_valid_apply:
            return Result.result_failed("you have matched with somebody: %d" %
                                        the_apply_id)
        OHHOLog.print_log("%d has no valid apply" % user_id)

        exclude_user_id_list = self.get_exclude_user_list(user_id)

        device_list = device_list_string.split(",")
        if "" in device_list:
            device_list.remove("")
        OHHOLog.print_log("source:")
        OHHOLog.print_log(device_list)
        device_list = self.clear_secondary_device(device_list)
        OHHOLog.print_log("clear secondary device:")
        OHHOLog.print_log(device_list)
        user_id_list = list()
        for identity in device_list:
            self.device.set_identity(identity)
            relation = self.device.get_relation_by_device()
            if relation:
                user_id_list.append(relation.user_id)
        OHHOLog.print_log("get user list")
        OHHOLog.print_log(user_id_list)
        OHHOLog.print_log("exclude user id list")
        OHHOLog.print_log(exclude_user_id_list)
        if user_id_list:
            user_id_list = OHHOOperation.list_minus_list(
                user_id_list, exclude_user_id_list)
            OHHOLog.print_log("clear exclude user")
            OHHOLog.print_log(user_id_list)

            user_id_list = self.clear_by_is_match(user_id_list)
            OHHOLog.print_log("clear match switch close user")
            OHHOLog.print_log(user_id_list)

            OHHOLog.print_log("clear self user")
            if user_id in user_id_list:
                user_id_list.remove(user_id)
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            meeting_user_id_list = self.meet.get_meeting_user_ids()
            OHHOLog.print_log("meeting user id list")
            OHHOLog.print_log(meeting_user_id_list)
            user_id_list = OHHOOperation.list_minus_list(
                user_id_list, meeting_user_id_list)
            OHHOLog.print_log("clear meeting user")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_met_not_end(user_id_list)
            OHHOLog.print_log("clear met but not end")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_meet_in24hour(user_id, user_id_list)
            OHHOLog.print_log("clear meet in 24 hours")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_friend(user_id, user_id_list)
            OHHOLog.print_log("clear friend")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            has_duplex_agree = self.has_duplex_agree(user_id, user_id_list,
                                                     base_url)
            if has_duplex_agree:
                return Result.result_success()
            else:
                user_id_list = self.duplex_match(user_id, user_id_list)
                OHHOLog.print_log(user_id_list)

                if user_id_list:
                    match_user_id = self.compute_main(user_id, user_id_list)
                    # OHHOLog.print_log("matched user list:")
                    # OHHOLog.print_log(matched_user_list)
                    #
                    # matched_user_list = self.sorted_by_rules(user_id, matched_user_list)
                    # user_tuple = matched_user_list[0]
                    # match_user_id = user_tuple[2]
                    # primary = user_tuple[3]
                    # secondary = user_tuple[4]
                    if match_user_id:
                        the_apply = self.add_apply(user_id, match_user_id)
                        if the_apply:
                            OHHOLog.print_log(
                                self.push_information(user_id, match_user_id,
                                                      the_apply.id, base_url))
                            OHHOLog.print_log(
                                self.push_information(match_user_id, user_id,
                                                      the_apply.id, base_url))
                        else:
                            OHHOLog.print_log("has valid apply!")
            return Result.result_success()
Пример #12
0
class LogicAddUser(object):
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition(
        )
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

        self.user_favourite_book = DBOHHOUserFavouriteBook()
        self.user_favourite_movie = DBOHHOUserFavouriteMovie()
        self.user_favourite_sport = DBOHHOUserFavouriteSport()
        self.user_favourite_music = DBOHHOUserFavouriteMusic()
        self.user_icon = DBOHHOUserIcon()
        self.user_description = DBOHHOUserDescription()
        self.user_impression = DBOHHOUserImpression()

    def add_user(self):
        cellphone = 10000000000
        identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            cellphone = int(user_obj.cellphone)

        for i in range(100):
            cellphone += 1
            # identity_card += 1
            while self.user.get_by_cellphone(cellphone):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id, identity_card)
            # self.add_user_match_condition(user_id)
            # self.add_user_configuration(user_id)
            # self.add_user_and_cellphone_relation(user_id)
            # self.add_user_and_device_imei(user_id)
            # self.add_user_and_device_relation(user_id)
            # self.add_user_description(user_id)
            # self.add_user_favourite_book(user_id)
            # self.add_user_favourite_movie(user_id)
            # self.add_user_favourite_music(user_id)
            # self.add_user_favourite_sport(user_id)
            # self.add_user_icon(user_id)
            # self.add_user_impression(user_id)

    def add_user_impression(self, user_id):
        data = dict()
        obj = OhhoRandom.get_user_impression()
        data["user_id"] = user_id
        data["another_user_id"] = obj.get("another_user_id", "")
        data["content_id"] = obj.get("content_id", "")
        data["apply_id"] = obj.get("apply_id", "")
        data["type"] = obj.get("type", "")
        self.user_impression.add(data)

    def add_user_icon(self, user_id):
        data = dict()
        obj = OhhoRandom.get_user_icon()
        data["user_id"] = user_id
        data["icon"] = obj.get("icon", "")
        data["is_head_sculpture"] = obj.get("is_head_sculpture", "")
        data["thumbnail"] = obj.get("thumbnail", "")
        self.user_icon.add(data)

    def add_user_favourite_sport(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_sport()
        data["user_id"] = user_id
        data["sport_id"] = obj.get("sport_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        self.user_favourite_sport.add(data)

    def add_user_favourite_music(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_music()
        data["user_id"] = user_id
        data["music_id"] = obj.get("music_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["album"] = obj.get("album", "")
        data["publisher"] = obj.get("publisher", "")
        data["singer"] = obj.get("singer", "")
        data["icon"] = obj.get("icon", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_music.add(data)

    def add_user_favourite_movie(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_movie()
        data["user_id"] = user_id
        data["movie_id"] = obj.get("movie_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        data["casts"] = obj.get("casts", "")
        data["genres"] = obj.get("genres", "")
        data["icon"] = obj.get("icon", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_movie.add(data)

    def add_user_favourite_book(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_book()
        data["user_id"] = user_id
        data["isbn"] = obj.get("isbn", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        data["icon"] = obj.get("icon", "")
        data["author"] = obj.get("author", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_book.add(data)

    def add_user_description(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["type"] = OhhoRandom.get_type()
        data["first"] = OhhoRandom.get_first()
        data["second"] = OhhoRandom.get_second()
        data["third"] = OhhoRandom.get_third()
        self.user_description.add(data)

    def add_user_and_device_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = OhhoRandom.get_device_id
        self.user_and_device_relation.add(data)

    def add_user_and_device_imei(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = OhhoRandom.get_device_id
        data["imei"] = OhhoRandom.get_imei()
        self.user_and_device_imei.add(data)

    def add_user_and_cellphone_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["cellphone_id"] = OhhoRandom.get_cellphone_id()
        self.user_and_cellphone_relation.add(data)

    def add_user_configuration(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["is_match"] = 1
        data["is_online"] = 1
        self.user_configuration.add(data)

    def add_user_match_condition(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["match_condition_id"] = OhhoRandom.get_match_condition_id()
        self.match_condition.add(data)

    def add_user_extension(self, user_id, identity_card):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        # data["identity_card"] = identity_card
        # data["real_name"] = ""
        data["nickname"] = "宝宝"
        data["birthday"] = OhhoRandom.get_birthday()
        # data["height"] = OhhoRandom.get_height()
        # data["hometown"] = OhhoRandom.get_hometown()
        # data["school"] = OhhoRandom.get_school()
        # data["company"] = OhhoRandom.get_company()
        # data["degree_id"] = OhhoRandom.get_degree_id()
        # data["favourite_live_city"] = OhhoRandom.get_favourite_live_city()
        # data["occupation_id"] = OhhoRandom.get_occupation_id()
        # data["position_id"] = OhhoRandom.get_position_id()

        self.user_extension.add(data)

    def add_user_token_table(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        self.token.token.add(token_dict)

    def add_user_table(self, cellphone="00000000000"):
        """添加用户 参数 """
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = cellphone
        data["country_code_id"] = country_code_id
        self.user.add(data)
        user = self.user.get_by_username(username)
        return user.id
Пример #13
0
 def __init__(self, user_id):
     self.user_id = user_id
     self.user = User()
     self.map = DBOHHOMapInformation()
     self.impression = DBOHHOUserImpression()
     self.extension = DBOHHOUserAccuracyExtension()
Пример #14
0
class LogicAddUserNew(object):
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition(
        )
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

        self.user_favourite_book = DBOHHOUserFavouriteBook()
        self.user_favourite_movie = DBOHHOUserFavouriteMovie()
        self.user_favourite_sport = DBOHHOUserFavouriteSport()
        self.user_favourite_music = DBOHHOUserFavouriteMusic()
        self.user_icon = DBOHHOUserIcon()
        self.user_description = DBOHHOUserDescription()
        self.user_impression = DBOHHOUserImpression()

        # self.cellphone = 10000000000
        # self.identity_id = 9000000000

    def add_user(self):
        cellphone = 10000000000
        identity_id = 9000000000
        for i in range(10):
            cellphone = cellphone + 1
            identity_id = identity_id + 1
            while self.user.get_by_cellphone(cellphone):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)
            self.add_user_configuration(user_id)
            # self.add_user_and_cellphone_relation(user_id)
            self.device.set_identity(identity_id)
            while self.device.get_by_identity():
                identity_id = identity_id + 1
            device_id = self.add_device(identity_id)
            self.add_user_and_device_imei(user_id, device_id)
            self.add_user_and_device_relation(user_id, device_id)
            match_condition_id = self.add_match_condition()
            print("match_condition_id:")
            print(match_condition_id)
            self.add_user_match_condition(user_id, match_condition_id)

    def add_device(self, identity_id):
        data = dict()
        data["identity_id"] = identity_id
        self.device.add(data)
        query = self.device.get_query()
        query = self.device.order_by_id_desc(query)
        obj = Operation.first(query)
        return obj.id

    def add_match_condition(self):
        data = dict()
        data["sex"] = OhhoRandom.get_sex()
        data["small_age"] = 0
        data["big_age"] = 150
        data["interest"] = OhhoRandom.get_user_match_interest()
        self.match_condition.add(data)
        query = self.match_condition.get_query()
        query = self.match_condition.order_by_id_desc(query)
        obj = Operation.first(query)
        return obj.id

    def add_user_and_device_relation(self, user_id, device_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = device_id
        self.user_and_device_relation.add(data)

    def add_user_and_device_imei(self, user_id, device_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = device_id
        data["imei"] = OhhoRandom.get_imei()
        self.user_and_device_imei.add(data)

    def add_user_and_cellphone_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["cellphone_id"] = OhhoRandom.get_cellphone_id()
        self.user_and_cellphone_relation.add(data)

    def add_user_configuration(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["is_match"] = 1
        data["is_online"] = 1
        self.user_configuration.add(data)

    def add_user_match_condition(self, user_id, match_condition_id):
        data = dict()
        data["user_id"] = user_id
        data["match_condition_id"] = match_condition_id
        self.record_user_and_match_condition.add(data)

    def add_user_extension(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        data["birthday"] = OhhoRandom.get_birthday()
        data["interest"] = OhhoRandom.get_user_interest()
        self.user_extension.add(data)

    def add_user_token_table(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        self.token.token.add(token_dict)

    def add_user_table(self, cellphone="00000000000"):
        """添加用户 参数 """
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = cellphone
        data["country_code_id"] = country_code_id
        self.user.add(data)
        user = self.user.get_by_username(username)
        return user.id
Пример #15
0
class LogicAddUser(object):
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition()
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

    # def gevent_add_user_test(self, cellphone):
    def add_user(self, number=10):
        gevent_list = [gevent.spawn(self.gevent_add_user_test, number) for i in range(2)]
        gevent.joinall(gevent_list)

    cellphone = 10000000000

    def gevent_add_user_test(self, number):
        global cellphone
        # identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            if user_obj.cellphone:
                cellphone = int(user_obj.cellphone)
        i = 0
        while i <= number:
            # OHHOLog.print_log(i)
            i += 1
            cellphone += 1
            while self.user.get_by_cellphone(str(cellphone)):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)

        print("for end")
        print("end")
    # def add_user(self, number=10):
    def gevent_add_user_test(self, number):
        global cellphone
        # identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            if user_obj.cellphone:
                cellphone = int(user_obj.cellphone)
        i = 0
        while i <= number:
            # OHHOLog.print_log(i)
            i += 1
            cellphone += 1
            while self.user.get_by_cellphone(str(cellphone)):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)

        print("for end")
        print("end")

    def add_user_commit_all(self, number=10):
        cellphone = 10000000000
        # identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            if user_obj.cellphone:
                cellphone = int(user_obj.cellphone)
        i = 1
        dic_list_token = list()
        dic_list_extension = list()
        while i <= number:
            # OHHOLog.print_log(i)
            print(i)
            i += 1
            cellphone += 1
            data = dict()
            while self.user.get_by_cellphone(str(cellphone)):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            token_dic = self.add_user_token_table_dic(user_id)
            extension_dic = self.add_user_extension_dic(user_id)
            dic_list_token.append(token_dic)
            dic_list_extension.append(extension_dic)

        self.token.token.bulk_add(dic_list_token)
        self.user_extension.bulk_add(dic_list_extension)
        print("for end")
        print("end")

    def add_user1(self, number=10):
        cellphone = 10000000000
        # identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            if user_obj.cellphone:
                cellphone = int(user_obj.cellphone)
        i = 0
        while i <= number:
            # OHHOLog.print_log(i)
            i += 1
            cellphone += 1
            while self.user.get_by_cellphone(str(cellphone)):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)

        print("for end")
        print("end")

    def add_user_impression(self, user_id):
        data = dict()
        obj = OhhoRandom.get_user_impression()
        data["user_id"] = user_id
        data["another_user_id"] = obj.get("another_user_id", "")
        data["content_id"] = obj.get("content_id", "")
        data["apply_id"] = obj.get("apply_id", "")
        data["type"] = obj.get("type", "")
        self.user_impression.add(data)

    def add_user_icon(self, user_id):
        data = dict()
        obj = OhhoRandom.get_user_icon()
        data["user_id"] = user_id
        data["icon"] = obj.get("icon", "")
        data["is_head_sculpture"] = obj.get("is_head_sculpture", "")
        data["thumbnail"] = obj.get("thumbnail", "")
        self.user_icon.add(data)

    def add_user_favourite_sport(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_sport()
        data["user_id"] = user_id
        data["sport_id"] = obj.get("sport_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        self.user_favourite_sport.add(data)

    def add_user_favourite_music(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_music()
        data["user_id"] = user_id
        data["music_id"] = obj.get("music_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["album"] = obj.get("album", "")
        data["publisher"] = obj.get("publisher", "")
        data["singer"] = obj.get("singer", "")
        data["icon"] = obj.get("icon", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_music.add(data)

    def add_user_favourite_movie(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_movie()
        data["user_id"] = user_id
        data["movie_id"] = obj.get("movie_id", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        data["casts"] = obj.get("casts", "")
        data["genres"] = obj.get("genres", "")
        data["icon"] = obj.get("icon", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_movie.add(data)

    def add_user_favourite_book(self, user_id):
        data = dict()
        obj = OhhoRandom.get_favourite_book()
        data["user_id"] = user_id
        data["isbn"] = obj.get("isbn", "")
        data["name"] = obj.get("name", "")
        data["description"] = obj.get("description", "")
        data["index"] = obj.get("index", "")
        data["icon"] = obj.get("icon", "")
        data["author"] = obj.get("author", "")
        data["url"] = obj.get("url", "")
        self.user_favourite_book.add(data)

    def add_user_description(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["type"] = OhhoRandom.get_type()
        data["first"] = OhhoRandom.get_first()
        data["second"] = OhhoRandom.get_second()
        data["third"] = OhhoRandom.get_third()
        self.user_description.add(data)

    def add_user_and_device_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = OhhoRandom.get_device_id
        self.user_and_device_relation.add(data)

    def add_user_and_device_imei(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = OhhoRandom.get_device_id
        data["imei"] = OhhoRandom.get_imei()
        self.user_and_device_imei.add(data)

    def add_user_and_cellphone_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["cellphone_id"] = OhhoRandom.get_cellphone_id()
        self.user_and_cellphone_relation.add(data)

    def add_user_configuration(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["is_match"] = 1
        data["is_online"] = 1
        self.user_configuration.add(data)

    def add_user_match_condition(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["match_condition_id"] = OhhoRandom.get_match_condition_id()
        self.match_condition.add(data)

    def add_user_extension(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        # data["identity_card"] = identity_card
        # data["real_name"] = ""
        data["nickname"] = "宝宝"
        data["birthday"] = OhhoRandom.get_birthday()
        # data["height"] = OhhoRandom.get_height()
        # data["hometown"] = OhhoRandom.get_hometown()
        # data["school"] = OhhoRandom.get_school()
        # data["company"] = OhhoRandom.get_company()
        # data["degree_id"] = OhhoRandom.get_degree_id()
        # data["favourite_live_city"] = OhhoRandom.get_favourite_live_city()
        # data["occupation_id"] = OhhoRandom.get_occupation_id()
        # data["position_id"] = OhhoRandom.get_position_id()

        self.user_extension.add(data)

    def add_user_extension_dic(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        data["nickname"] = "宝宝"
        data["birthday"] = OhhoRandom.get_birthday()
        return data

    def add_user_token_table_dic(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        # self.token.token.add(token_dict)
        return token_dict

    def add_user_token_table(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        self.token.token.add(token_dict)

    def add_user_table(self, cellphone="00000000000"):
        """添加用户 参数 """
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = cellphone
        data["country_code_id"] = country_code_id
        # time1 = time.time()
        self.user.add(data)
        # print("user_id")
        # print(self.user.model.id[0])
        user = self.user.get_by_username(username)
        # time2 = time.time()
        # time3 = time2 - time1
        # print("user insert")
        # print(time3)
        return user.id

    def insert_table(self):
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = "13828838383"
        data["country_code_id"] = country_code_id
        time1 = time.time()
        self.user.add(data)
        time2 = time.time()
        time3 = time2 - time1
        print("user insert")
        print(time3)
Пример #16
0
class LogicAddUser(object):
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition()
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()

    def add_user(self, number=10):
        cellphone = 10000000000
        # identity_card = 100000000000000000
        user_query = self.user.get_query()
        user_query = self.user.order_by_id_desc(user_query)
        user_obj = Operation.first(user_query)
        if user_obj:
            if user_obj.cellphone:
                cellphone = int(user_obj.cellphone)
        i = 0
        while i <= number:
            i += 1
            cellphone += 1
            while self.user.get_by_cellphone(str(cellphone)):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)

        print("for end")
        print("end")

    def add_func(self, number, cellphone):



    def add_user_extension(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        # data["identity_card"] = identity_card
        # data["real_name"] = ""
        data["nickname"] = "宝宝"
        data["birthday"] = OhhoRandom.get_birthday()

        self.user_extension.add(data)

    def add_user_token_table(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        self.token.token.add(token_dict)

    def add_user_table(self, cellphone="00000000000"):
        """添加用户 参数 """
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = cellphone
        data["country_code_id"] = country_code_id
        self.user.add(data)
        user = self.user.get_by_username(username)
        return user.id
Пример #17
0
class User(object):
    def __init__(self, index=0):
        self.user = DBOHHOUser(index)
        self.user_accuracy_extension = DBOHHOUserAccuracyExtension(index)
        self.user_description = DBOHHOUserDescription(index)
        self.user_favourite_book = DBOHHOUserFavouriteBook(index)
        self.user_favourite_movie = DBOHHOUserFavouriteMovie(index)
        self.user_favourite_music = DBOHHOUserFavouriteMusic(index)
        self.user_favourite_sport = DBOHHOUserFavouriteSport(index)
        self.user_icon = DBOHHOUserIcon(index)
        self.user_impression = DBOHHOUserImpression(index)

    def add_some(self, instance, data):
        if instance and data:
            instance.add_without_commit(data)

    def add_extension(self, data):
        self.add_some(self.user_accuracy_extension, data)

    def add_description(self, data):
        self.add_some(self.user_description, data)

    def add_book(self, data):
        self.add_some(self.user_favourite_book, data)

    def add_movie(self, data):
        self.add_some(self.user_favourite_movie, data)

    def add_music(self, data):
        self.add_some(self.user_favourite_music, data)

    def add_sport(self, data):
        self.add_some(self.user_favourite_sport, data)

    def add_icon(self, data):
        self.add_some(self.user_icon, data)

    def add_impression(self, data):
        self.add_some(self.user_impression, data)

    def add_basic(self, user_id, extension, description_I_am,
                  description_I_like, description_I_unlike,
                  description_I_hope):
        try:
            user_extension = self.user_accuracy_extension.get_by_user(user_id)
            if user_extension:
                self.user_accuracy_extension.update_without_commit(
                    user_extension, extension)
            else:
                self.add_extension(extension)

            query = self.user_description.get_query()
            user_description = self.user_description.get_by_user(
                query, user_id)

            if description_I_am:
                I_am = self.user_description.get_I_am(user_description)
                I_am = self.user_description.order_by_id_desc(I_am)
                I_am = self.user_description.first(I_am)
                if I_am:
                    self.user_description.update_without_commit(
                        I_am, description_I_am)
                else:
                    self.user_description.add_I_am(description_I_am)

            if description_I_like:
                I_like = self.user_description.get_I_like(query)
                I_like = self.user_description.order_by_id_desc(I_like)
                I_like = self.user_description.first(I_like)
                if I_like:
                    self.user_description.update_without_commit(
                        I_like, description_I_like)
                else:
                    self.user_description.add_I_like(description_I_like)

            if description_I_unlike:
                I_unlike = self.user_description.get_I_unlike(query)
                I_unlike = self.user_description.order_by_id_desc(I_unlike)
                I_unlike = self.user_description.first(I_unlike)
                if I_unlike:
                    self.user_description.update_without_commit(
                        I_unlike, description_I_unlike)
                else:
                    self.user_description.add_I_unlike(description_I_unlike)

            if description_I_hope:
                I_hope = self.user_description.get_I_hope(query)
                I_hope = self.user_description.order_by_id_desc(I_hope)
                I_hope = self.user_description.first(I_hope)
                if I_hope:
                    self.user_description.update_without_commit(
                        I_hope, description_I_hope)
                else:
                    self.user_description.add_I_hope_she_is(description_I_hope)

            return Operation.commit()
        except Exception as ex:
            OHHOLog.print_log(ex)
            return False