Esempio n. 1
0
def add_friend(phone):
    user_id = session.get('user_id')
    user_model = User.query.filter(User.id == user_id).first()
    friend_model = User.query.filter(User.phone == phone).first()
    if request.method == 'GET':
        return render_template('search.html',
                               user=user_model,
                               friend=friend_model)
    else:
        test = Friend.query.filter(Friend.friend_id == friend_model.id,
                                   Friend.user_id == user_id).first()
        if test:
            print('1')
            return render_template('search.html',
                                   user=user_model,
                                   friend=friend_model)
        else:
            print('2')
            friend = Friend(friend_id=friend_model.id)
            friend.user_id = session.get('user_id')
            db.session.add(friend)
            db.session.commit()
            print('3')
            return render_template('search.html',
                                   user=user_model,
                                   friend=friend_model)
Esempio n. 2
0
def parse_friends():
    # # print(os.getcwd() + '/' + friends_html)
    # print(os.getcwd() + '/' + 'database/index1200friends.html')
    # driver.get('file:///' + os.getcwd() + '/' + friends_html)
    list_of_friends = driver.find_elements_by_class_name('gfomwglr')
    print(len(list_of_friends))
    div_fb_link_counter = 1
    for e in list_of_friends:
        try:
            mutual_friends_number = driver.find_element_by_xpath(
                '//*[@id="mount_0_0"]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div[3]/div['
                + str(div_fb_link_counter) +
                ']/div[2]/div[2]/span/div/div/a').text.split()
        except:
            print("No mutual friends")
            mutual_friends_number[0] = "0"
        try:
            text = driver.find_element_by_xpath(
                '//*[@id="mount_0_0"]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div[3]/div['
                + str(div_fb_link_counter) + ']/div[2]/div[1]/a/span').text
            link = driver.find_element_by_xpath(
                '//*[@id="mount_0_0"]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div[3]/div['
                + str(div_fb_link_counter) +
                ']/div[2]/div[1]/a').get_attribute('href')

            x = text.split()
            name = ''
            for i in x[:-1]:
                name += i
            surname = x[-1]
            create_friends_list(
                Friend(name, surname, mutual_friends_number[0], link))
        except:
            print("ELement not found")
        div_fb_link_counter += 1
Esempio n. 3
0
def add_contact(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        flash('The user does not exist!')
        return redirect(url_for('search'))
    if username == current_user.username:
        flash('Can not add yourself!')
        return redirect(url_for('search'))

    friend = Friend.query.filter_by(uid=current_user.id, fid=user.id).first()
    if friend is not None:
        flash('You have already added the contact!')
        return redirect(url_for('search'))
    friend = Friend(uid=current_user.id, fid=user.id)
    friend2 = Friend(uid=user.id, fid=current_user.id)
    db.session.add(friend)
    db.session.add(friend2)
    db.session.commit()
    flash('Add success!')
    return redirect(url_for('contacts'))
Esempio n. 4
0
def acceptRequest(requestFrom):
    if request.method == 'POST':
        data = json.loads(request.get_data())
        if data['uemail'] in session:
            db.session.add(Friend(session[data['uemail']], requestFrom))
            db.session.commit()
            return jsonify({'status': 1})
        else:
            return jsonify({
                'status': 0,
                'message': 'User haven\'t login yet!'
            })
Esempio n. 5
0
def addFriend(friend_id):
    """ Add friend to user """

    user = g.user
    friend = User.query.get(friend_id)

    newFriend = Friend(user_being_followed_id=user.id,
                       user_following_id=friend.id)

    db.session.add(newFriend)
    db.session.commit()

    return redirect(f"/user/friends")
Esempio n. 6
0
def wow_post():
    username = session.get('username')
    name = request.form.get('name')
    realm = request.form.get('realm')

    if name and realm:  # make sure name and realm aren't empty
        ratings = wow_arena_call(name, realm)
        if ratings:
            new_friend = Friend(username, name.capitalize(), realm.capitalize(
            ), ratings['twos'], ratings['threes'], ratings['rbg'])
            db.session.add(new_friend)
            db.session.commit()

    return redirect("/")
Esempio n. 7
0
def add_friend():
    """Add contact information for a friend into the database."""

    friend_data = json.loads(request.data)
    name = friend_data['name']
    phone = clean_phone_number(friend_data['phone'])
    value = False

    if 'user_id' in session:
        user_id = session['user_id']

        new_friend = Friend(user_id=user_id, name=name, phone=phone)
        value = update_db(new_friend)

    return jsonify({'value': value})
Esempio n. 8
0
def add_friendship():

    user_1 = session['user_id']
    user_2 = request.form.get('friend_user_id')

    friendship = Friend(user_1=user_1,
                        user_2=user_2,
                        active=True,
                        friended_on=datetime.today(),
                        modified_on=datetime.today())

    friendship.save()

    flash('Friend added successfully.', success_flash)

    return redirect('/feed')
Esempio n. 9
0
def load_friends():
    """Reads in friends.txt and adds to database."""

    with open('seed_data/friends.txt') as f:
        for row in f:
            row = row.strip()
            user_id, name, raw_phone = row.split('|')

            phone_split = raw_phone.split('x')
            phone = clean_phone_number(phone_split[0])

            entry = Friend(user_id=user_id, name=name, phone=phone)

            db.session.add(entry)

    db.session.commit()
Esempio n. 10
0
def friends():
    summary, temp = get_weather()
    user_id = current_user.id

    if request.method == 'POST':
        name = request.form.get('new-friend').strip()
        new_friend = Friend(name=name, user_id=user_id)
        db.session.add(new_friend)
        db.session.commit()
        return redirect(url_for('friends'))

    friends_objects = User.query.filter_by(id=user_id).first().friends
    return render_template('friends.html',
                           summary=summary,
                           temp=temp,
                           friends=sorted(friends_objects,
                                          key=lambda x: x.name))
Esempio n. 11
0
def send(id1, id2, room):
    print(room)
    if room == "None":
        flash("Please create own room then send", "danger")
        return redirect(url_for("dashbord"))
    else:
        fcheck = Friend.query.filter((Friend.send == id1)
                                     & (Friend.receive == id2)).first()
        if fcheck:
            flash("You are already send request", "danger")
        else:
            F = Friend(send=id1, receive=id2, room_name=room)
            db.session.add(F)
            db.session.commit()
            db.session.close()
            flash("Your request successfully send")
        return redirect(url_for("dashbord"))
Esempio n. 12
0
    def __construct_friend_list(self):
        name_counter = Counter()
        inbox_messages_path = paths.get_message_inbox_path(self.root_path)
        friends: List[Friend] = []
        self.__name_inference_counter = Counter()
        for inbox in os.scandir(inbox_messages_path):
            if not inbox.is_dir():
                continue
            msg_one_json = utils.read_json(os.path.join(inbox, "message_1.json"))

            thread_type: str = msg_one_json["thread_type"]
            # only dealing with 1-on-1 messages, not groups yet.
            if thread_type != "Regular":
                continue

            printable_name: str = msg_one_json["title"].strip()
            formatted_name: str = printable_name.replace(" ", "").lower()

            # to only load messages from people that you are friend with
            if formatted_name not in self._friend_names:
                continue

            # to deal with duplicate names (both first and last)
            if formatted_name in name_counter:
                formatted_name += "_" + str(name_counter[formatted_name])
            name_counter[formatted_name] += 1

            messages, oldest_message = self.__read_messages(inbox.path)

            friends.append(
                Friend(
                    name=formatted_name,
                    printable_name=printable_name,
                    timestamp=oldest_message,
                    messages=messages
                )
            )
        self.sender_name = self.__name_inference_counter.most_common(1)[0][0].lower().replace(" ", "")
        return friends
Esempio n. 13
0
def add_friend(secure_channel, request):
    ''' 添加好友 '''
    username = secure_channel_to_username[secure_channel]
    to_username = request.strip()

    session = Session()
    from_user = session.query(User).\
        filter(User.username == username).\
        first()
    user = session.query(User).\
        filter(User.username == to_username).first()

    result = {'success': False, 'message': ''}
    if not user:
        result['message'] = '用户不存在!'
        secure_channel.send(Command.ADD_FRIEND_RESULT, result)
        return

    if user.username == username:
        result['message'] = "无法添加自己为好友!"
        secure_channel.send(Command.ADD_FRIEND_RESULT, result)
        return

    applyed = session.query(Friend).\
        filter(Friend.from_user == username,
               Friend.to_user == user.username,
               Friend.accepted == False).count()
    if applyed:
        result['message'] = '已经申请过!'
        secure_channel.send(Command.ADD_FRIEND_RESULT, result)
        return

    if _is_friend(session, username, user.username):
        result['message'] = '好友已存在!'
        secure_channel.send(Command.ADD_FRIEND_RESULT, result)
        return

    requested = session.query(Friend).\
        filter(Friend.from_user == user.username,
               Friend.to_user == username,
               Friend.accepted == False).\
        first()
    if requested:
        requested.accepted = True
        session.add(requested)
        session.commit()
        contact_info = user.username
        secure_channel.send(Command.NEW_CONTACT, contact_info)
        if user.username in username_to_secure_channel:
            contact_info = from_user.username
            username_to_secure_channel[user.username].\
                send(Command.NEW_CONTACT, contact_info)
        return

    friend = Friend(from_user=from_user.username, to_user=user.username)
    session.add(friend)
    session.commit()
    result['success'] = True
    secure_channel.send(Command.ADD_FRIEND_RESULT, result)

    if user.username in username_to_secure_channel:
        data = from_user.username
        username_to_secure_channel[user.username].\
            send(Command.INCOMMING_FRIEND_REQUEST, data)
Esempio n. 14
0
def save_friends(user_id, friend_jarray):
    for name in friend_jarray:
        friend = Friend()
        friend.user_id = user_id
        friend.friends = name
        friend.save()
Esempio n. 15
0
def immed():
    if request.method == 'GET':
        # is_login = request.cookies.get('name')
        is_login = session.get('name')
        if not is_login:
            print('未登录')
            return redirect('/login/')
        else:
            return render_template('immed.html', is_login=is_login)
    else:
        print(request.form)
        # id = request.cookies.get('id')
        id = session.get('name')
        user = User.query.filter_by(iphone=id).first()
        nickname = request.form.get('nickname')
        sex = request.form.get('sex')
        birth = request.form.get('birth')
        age = request.values.get("age")
        high = request.form.get('high')
        image1 = request.files.get('image')
        filename = secure_filename(image1.filename)
        img = filename
        image1.save(os.path.join(BASE_DIR + '/static/home/media', filename))
        education = request.form.get('education')
        profession = request.form.get('profession')
        property = request.form.get('property')
        income = request.form.get('income')
        residence = request.form.get('residence')
        register = request.form.get('register')
        qq = request.form.get('qq')
        wechat = request.form.get('wechat')
        email = request.form.get('email')
        f_age = request.form.get('f_age')
        f_high = request.form.get('f_high')
        f_income = request.form.get('f_income')
        f_education = request.form.get('f_education')
        f_register = request.form.get('f_register')
        f_residence = request.form.get('f_residence')
        try:
            user_info = User_info(user_id=user.id,
                                  nickname=nickname,
                                  image=img,
                                  sex=sex,
                                  birth=birth,
                                  age=age,
                                  high=high,
                                  education=education,
                                  profession=profession,
                                  income=income,
                                  property=property,
                                  residence=residence,
                                  register=register,
                                  qq=qq,
                                  wechat=wechat,
                                  email=email)
            friend = Friend(
                user_id=user.id,
                f_age=f_age,
                f_high=f_high,
                f_education=f_education,
                f_income=f_income,
                f_register=f_register,
                f_residence=f_residence,
            )
            db.session.add(user_info)
            db.session.add(friend)
            db.session.commit()
        except Exception as e:
            print(e)
            return Response('用户信息提交失败')
        return redirect('/')