Example #1
0
def profile_post(username):
    """
    Update user's profile or password

    :param username: username of the user
    :type username: string
    :rtype: profile page of the user

    Note:
        Use 'action' param to judge whether to update profile or password
    """
    user = User.get(username)
    ownername = request.get_cookie('username', secret=COOKIES_SECRET)
    owner = User.get(ownername)
    action = request.GET.get('action', '')
    if ownername == username:
        if action == 'profile':
            avatar = request.files.avatar
            if avatar and avatar.file:
                avatar_new = 'images/%s' % username
                avatar_file = file(avatar_new, 'w')
                print >> avatar_file, avatar.file.read()
                avatar_file.close()
            res, msg = user.update(
                name=request.forms.name,
                gender=request.forms.gender,
                hometown=request.forms.hometown,
            )
        elif action == 'password':
            old_pw = request.forms.get('old_pw')
            new_pw1 = request.forms.get('new_pw1')
            new_pw2 = request.forms.get('new_pw2')
            res, msg = user.update_password(old_pw, new_pw1, new_pw2)
        elif action == 'tweet':
            res, msg = Tweet.add(
                username=username,
                text=request.forms.text,
                created_at=datetime.datetime.now().strftime(
                    '%Y-%m-%d %H:%M:%S'),
            )
        if res:
            redirect('/%s/' % username)
        else:
            return template('%s_update' % action,
                            user=user,
                            msg=msg,
                            ownername=ownername)
    elif action == 'follow':
        owner.follow(username)
    elif action == 'unfollow':
        owner.unfollow(username)
    redirect('/%s/' % username)
Example #2
0
def profile_post(username):
    """
    Update user's profile or password

    :param username: username of the user
    :type username: string
    :rtype: profile page of the user

    Note:
        Use 'action' param to judge whether to update profile or password
    """
    user = User.get(username)
    ownername = request.get_cookie('username', secret=COOKIES_SECRET)
    owner = User.get(ownername)
    action = request.GET.get('action', '')
    if ownername == username:
        if action == 'profile':
            avatar = request.files.avatar
            username_new = request.forms.username or username
            avatar_new = user.avatar
            if avatar and avatar.file:
                avatar_new = 'images/avatar_%s%s' % (
                    username,
                    os.path.splitext(avatar.filename)[-1],
                )
                avatar_file = file(avatar_new, 'w')
                print >> avatar_file, avatar.file.read()
                avatar_file.close()
            res, msg = user.update(username_new, avatar_new)
            return template('profile_update', user=user, msg=msg)
        elif action == 'password':
            old_pw = request.forms.get('old_pw')
            new_pw1 = request.forms.get('new_pw1')
            new_pw2 = request.forms.get('new_pw2')
            res, msg = user.update_password(old_pw, new_pw1, new_pw2)
            return template('password_update', user=user, msg=msg)
        elif action == 'tweet':
            param = {
                'username':
                username,
                'text':
                request.forms.text,
                'created_at':
                datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
            }
            res, msg = Tweet.add(**param)
            return template('tweet_update', user=user, tweet_msg=msg)
        elif action == 'follow':
            owner.follow(username)
        elif action == 'unfollow':
            owner.unfollow(username)
    redirect('/%s/' % username)
Example #3
0
def profile_post(username):
    """
    Update user's profile or password

    :param username: username of the user
    :type username: string
    :rtype: profile page of the user

    Note:
        Use 'action' param to judge whether to update profile or password
    """
    user = User.get(username)
    ownername = request.get_cookie('username', secret=COOKIES_SECRET)
    owner = User.get(ownername)
    action = request.GET.get('action', '')
    if ownername == username:
        if action == 'profile':
            avatar = request.files.avatar
            if avatar and avatar.file:
                avatar_new = 'images/%s' % username
                avatar_file = file(avatar_new, 'w')
                print >> avatar_file, avatar.file.read()
                avatar_file.close()
            res, msg = user.update(
                name=request.forms.name,
                gender=request.forms.gender,
                hometown=request.forms.hometown,
            )
        elif action == 'password':
            old_pw = request.forms.get('old_pw')
            new_pw1 = request.forms.get('new_pw1')
            new_pw2 = request.forms.get('new_pw2')
            res, msg = user.update_password(old_pw, new_pw1, new_pw2)
        elif action == 'tweet':
            res, msg = Tweet.add(
                username = username,
                text = request.forms.text,
                created_at =
                    datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
            )
        if res:
            redirect('/%s/' % username)
        else:
            return template('%s_update' % action, user=user, msg=msg,
                ownername=ownername)
    elif action == 'follow':
        owner.follow(username)
    elif action == 'unfollow':
        owner.unfollow(username)
    redirect('/%s/' % username)
Example #4
0
def profile_post(username):
    """
    Update user's profile or password

    :param username: username of the user
    :type username: string
    :rtype: profile page of the user

    Note:
        Use 'action' param to judge whether to update profile or password
    """
    user = User.get(username)
    ownername = request.get_cookie("username", secret=COOKIES_SECRET)
    owner = User.get(ownername)
    action = request.GET.get("action", "")
    if ownername == username:
        if action == "profile":
            avatar = request.files.avatar
            username_new = request.forms.username or username
            avatar_new = user.avatar
            if avatar and avatar.file:
                avatar_new = "images/avatar_%s%s" % (username, os.path.splitext(avatar.filename)[-1])
                avatar_file = file(avatar_new, "w")
                print >> avatar_file, avatar.file.read()
                avatar_file.close()
            res, msg = user.update(username_new, avatar_new)
            return template("profile_update", user=user, msg=msg)
        elif action == "password":
            old_pw = request.forms.get("old_pw")
            new_pw1 = request.forms.get("new_pw1")
            new_pw2 = request.forms.get("new_pw2")
            res, msg = user.update_password(old_pw, new_pw1, new_pw2)
            return template("password_update", user=user, msg=msg)
        elif action == "tweet":
            param = {
                "username": username,
                "text": request.forms.text,
                "created_at": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            }
            res, msg = Tweet.add(**param)
            return template("tweet_update", user=user, tweet_msg=msg)
        elif action == "follow":
            owner.follow(username)
        elif action == "unfollow":
            owner.unfollow(username)
    redirect("/%s/" % username)
Example #5
0
def main():
    """docstring for main"""

    data = file('data/petster-hamster/ent.petster-hamster')
    for item in data.readlines():
        item = item.decode('utf8')
        # print repr(item)
        # print type(item)
        # print item
        if not item.startswith('%'):
            res = INFO_PATTERN.findall(item)
            info = dict(zip(KEYS, res))
            print info['username']
            res, user = User.add(
                username=info['username'],
                password='******' % info['username'],
                password_confirm='pyneo4jet%s' % info['username'],
                invitation=INVITATION_CODE,
            )
            user.update(
                name=info['name'],
                gender=info['gender'],
                hometown=info['hometown'],
            )
            for key in KEYS:
                res, msg = Tweet.add(info['username'],
                    'My %s is %s' % (key, info[key]),
                    (
                        datetime.datetime.now() -
                        datetime.timedelta(days=random.randrange(0, 365)) -
                        datetime.timedelta(seconds=random.randrange(0, 86400))
                    ).strftime('%Y-%m-%d %H:%M:%S'),
                )
                if not res:
                    print msg
                    print key
                    print info[key]
                    raw_input()
    data.close()

    data = file('data/petster-hamster/out.petster-hamster')
    for item in data.readlines():
        # print repr(item)
        # raw_input()
        if not item.startswith('%'):
            username1, username2 = item.strip().split(' ')
            print username1, username2
            # raw_input()
            user1 = User.get(username1)
            user2 = User.get(username2)
            if user1 and user2:
                if (int(username1) + int(username2)) % 2 == 0:
                    res, msg = user2.follow(username1)
                else:
                    res, msg = user1.follow(username2)
                if not res:
                    print msg
                    raw_input()
    data.close()

    db.shutdown()
Example #6
0
def main():
    """docstring for main"""

    data = file('data/petster-hamster/ent.petster-hamster')
    for item in data.readlines():
        item = item.decode('utf8')
        # print repr(item)
        # print type(item)
        # print item
        if not item.startswith('%'):
            res = INFO_PATTERN.findall(item)
            info = dict(zip(KEYS, res))
            print info['username']
            res, user = User.add(
                username=info['username'],
                password='******' % info['username'],
                password_confirm='pyneo4jet%s' % info['username'],
                invitation=INVITATION_CODE,
            )
            user.update(
                name=info['name'],
                gender=info['gender'],
                hometown=info['hometown'],
            )
            for key in KEYS:
                res, msg = Tweet.add(
                    info['username'],
                    'My %s is %s' % (key, info[key]),
                    (datetime.datetime.now() -
                     datetime.timedelta(days=random.randrange(0, 365)) -
                     datetime.timedelta(seconds=random.randrange(0, 86400))
                     ).strftime('%Y-%m-%d %H:%M:%S'),
                )
                if not res:
                    print msg
                    print key
                    print info[key]
                    raw_input()
    data.close()

    data = file('data/petster-hamster/out.petster-hamster')
    for item in data.readlines():
        # print repr(item)
        # raw_input()
        if not item.startswith('%'):
            username1, username2 = item.strip().split(' ')
            print username1, username2
            # raw_input()
            user1 = User.get(username1)
            user2 = User.get(username2)
            if user1 and user2:
                if (int(username1) + int(username2)) % 2 == 0:
                    res, msg = user2.follow(username1)
                else:
                    res, msg = user1.follow(username2)
                if not res:
                    print msg
                    raw_input()
    data.close()

    db.shutdown()