Пример #1
0
def search_top_users(term,
                     user_group,
                     db_con,
                     search_count=twitter_settings.max_users_search_count):
    """ Searches for the top users matching a specific term, and stores
        them in the database. Use search_users for users currently tweeting
        about a specific topic

        returns a list of user objects
    """
    query_params = "?q={0}&count={1}".format(urllib.quote(term), search_count)

    logging.info("Searching for top users for {0}".format(term))

    # encode the query for use in a url
    query_url = "https://api.twitter.com/1.1/users/search.json{0}".format(
        query_params)

    logging.debug("Twitter API call: {0}".format(query_url))
    json_data = twitterreq(query_url, "GET")
    logging.info("Searching for {0} completed".format(term))

    # save the results
    users = json_data

    for user in users:
        db.insert_user(db_con, user, user_group)
        if "screen_name" in user and user["screen_name"]:
            print("{0}:{1}".format(user["screen_name"], user_group))

    logging.info("Results written to database")
    return users
Пример #2
0
def test_get_all_lists_empty(req_context):
    from database import insert_user
    from database import get_all_users_lists
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    lists = get_all_users_lists(user_id)
    assert len(lists) == 0
Пример #3
0
def oauth():
    global user
    url = request.url
    print(url)
    text = re.sub('.*\?', '', url)
    params = parser(text)
    user = OAuth1Session(CK, CS, params['oauth_token'], params['oauth_verifier'])
    res = user.post('https://api.twitter.com/oauth/access_token', params)
    params = parser(res.text)
    print(params)
    AK, AS = params['oauth_token'], params['oauth_token_secret']
    id_ = params['user_id']

    user = OAuth1Session(CK, CS, AK, AS)
    
    with open('datas.json', 'r') as f:
        obj = json.load(f)

    if is_exist(id_):
        print('update')
        update_user(id_, AK, AS)
    else:
        print('insert')
        insert_user(id_, AK, AS)

    return redirect(url_for('application'))
Пример #4
0
def test_get_user_name(req_context):
    from database import insert_user, get_user_name
    name = "Bob"
    insert_user(name, "pass", "email")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    actual = get_user_name(user_id)
    assert actual == name
Пример #5
0
def test_get_all_lists_empty(req_context):
    from database import insert_user
    from database import get_all_users_lists
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    lists = get_all_users_lists(user_id)
    assert len(lists) == 0
Пример #6
0
def add_new_user(user):
    """\
    Insert an <User> object into the database

    :param user: an object of the <User> type
    """
    database.insert_user(user)
Пример #7
0
def test_get_login_user(req_context):
    from database import insert_user, get_login_user
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    actual = get_login_user("Test User")
    assert actual[0]['user_id'] == user_id
    assert actual[0]['user_passwd'] == "pass"
Пример #8
0
def test_get_user_name(req_context):
    from database import insert_user, get_user_name
    name = "Bob"
    insert_user(name, "pass", "email")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    actual = get_user_name(user_id)
    assert actual == name
Пример #9
0
def search_users(term, user_group, db_con,
                 search_count=twitter_settings.max_search_tweets_count):
    """ searches for users who have recently posted tweets with containing the term and
        stores them in the database

        returns the list of user objects
    """
    query_params = "?q={0}&count={1}".format(urllib.quote(term), search_count)
    # don't include retweets when searching for users
    query_params += urllib.quote(" exclude:retweets")

    logging.info("Searching for users who tweeted about {0}".format(term))

    # encode the query for use in a url
    query_url = "https://api.twitter.com/1.1/search/tweets.json{0}".format(query_params)

    logging.debug("Twitter API call: {0}".format(query_url))
    json_data = twitterreq(query_url, "GET")
    logging.info("Searching for {0} completed".format(term))

    if not "statuses" in json_data:
        logging.error("Error {0}".format(json_data))

    # save the results
    tweets = json_data["statuses"]
    # extract the user object from the tweet object
    users = [tweet["user"] for tweet in tweets]

    for user in users:
        db.insert_user(db_con, user, user_group)

    logging.info("Results written to database")
    return users
Пример #10
0
def test_get_login_user(req_context):
    from database import insert_user, get_login_user
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    actual = get_login_user("Test User")
    assert actual[0]['user_id'] == user_id
    assert actual[0]['user_passwd'] == "pass"
Пример #11
0
def search_top_users(term, user_group, db_con,
                     search_count=twitter_settings.max_users_search_count):
    """ Searches for the top users matching a specific term, and stores
        them in the database. Use search_users for users currently tweeting
        about a specific topic

        returns a list of user objects
    """
    query_params = "?q={0}&count={1}".format(urllib.quote(term), search_count)

    logging.info("Searching for top users for {0}".format(term))

    # encode the query for use in a url
    query_url = "https://api.twitter.com/1.1/users/search.json{0}".format(query_params)

    logging.debug("Twitter API call: {0}".format(query_url))
    json_data = twitterreq(query_url, "GET")
    logging.info("Searching for {0} completed".format(term))

    # save the results
    users = json_data

    for user in users:
        db.insert_user(db_con, user, user_group)
        if "screen_name" in user and user["screen_name"]:
            print("{0}:{1}".format(user["screen_name"], user_group))

    logging.info("Results written to database")
    return users
Пример #12
0
def test_get_all_user_names(req_context):
    from database import insert_user, get_all_user_names
    users = ("Mark", "Michelle")
    insert_user(users[0], "password", "*****@*****.**")
    insert_user(users[1], "password2", "*****@*****.**")
    actual = get_all_user_names()
    for name in actual:
        assert name in users
Пример #13
0
def record(request):
    token = request.GET.get('token')
    session = scrobble.get_session(token)
    user_ID = request.GET.get('username')
    record_time = datetime.now() - timedelta(minutes=20)
    record_time = record_time.strftime('%Y-%m-%d %H:%M:%S')
    database.insert_user(user_ID, session, record_time)
    return render(request, 'third.html')
Пример #14
0
def test_get_all_user_names(req_context):
    from database import insert_user, get_all_user_names
    users = ("Mark", "Michelle")
    insert_user(users[0], "password", "*****@*****.**")
    insert_user(users[1], "password2", "*****@*****.**")
    actual = get_all_user_names()
    for name in actual:
        assert name in users
Пример #15
0
def test_make_user(req_context):
    from database import insert_user
    expected = ("My Name", "My Password", "*****@*****.**")
    insert_user(*expected)
    rows = run_independent_query("SELECT * FROM users")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #16
0
def test_make_user(req_context):
    from database import insert_user
    expected = ("My Name", "My Password", "*****@*****.**")
    insert_user(*expected)
    rows = run_independent_query("SELECT * FROM users")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #17
0
def test_update_user_color(req_context):
    from database import insert_user, user_color_update
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ('green', user_id)
    user_color_update(*expected)
    rows = run_independent_query("SELECT user_id, icon_color FROM users")
    for val in expected:
        assert val in rows[0]
Пример #18
0
def test_update_user_info(req_context):
    from database import insert_user, update_user_info
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("This is my user info!", user_id)
    update_user_info(*expected)
    rows = run_independent_query("SELECT user_id, user_info FROM users")
    for val in expected:
        assert val in rows[0]
Пример #19
0
def test_update_user_color(req_context):
    from database import insert_user, user_color_update
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ('green', user_id)
    user_color_update(*expected)
    rows = run_independent_query("SELECT user_id, icon_color FROM users")
    for val in expected:
        assert val in rows[0]
Пример #20
0
def test_update_user_info(req_context):
    from database import insert_user, update_user_info
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("This is my user info!", user_id)
    update_user_info(*expected)
    rows = run_independent_query("SELECT user_id, user_info FROM users")
    for val in expected:
        assert val in rows[0]
Пример #21
0
def registration_handler(data):
    logger.debug("Registration %s", data)
    doublename = data.get('doubleName').lower()
    email = data.get('email')
    sid = request.sid
    publickey = data.get('publicKey')
    user = db.getUserByName(conn, doublename)
    if (user is None):
        update_sql = "INSERT into users (double_name, sid, email, public_key) VALUES(?,?,?,?);"
        db.insert_user(conn, update_sql, doublename, sid, email, publickey)
Пример #22
0
def test_get_all_lists(req_context):
    from database import get_all_users_lists, make_list, insert_user
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("My Title", "My description", user_id)
    make_list(*expected)
    lists = get_all_users_lists(user_id)
    assert len(lists) == 1
    for l in lists:
        assert expected[0] == l['title']
        assert expected[1] == l['description']
Пример #23
0
def test_update_list_title_test(req_context):
    from database import insert_user, make_list, update_list_title_text
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    expected = ("New Title", "New description")
    update_list_title_text(*expected, list_id=list_id)
    rows = run_independent_query("SELECT title, description FROM lists")
    for val in expected:
        assert val in rows[0]
Пример #24
0
def test_delete_list(req_context):
    from database import insert_user, make_list, insert_list_item
    from database import delete_list, get_all_users_lists
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    insert_list_item(list_id, "Do this")
    delete_list(list_id)
    lists = get_all_users_lists(user_id)
    assert len(lists) == 0
Пример #25
0
    def dialog_callback(self, update, context):
        #        self.pp.flush()
        if context.user_data and self._id in context.user_data and context.user_data[
                self._id]['state'] != []:
            if context.user_data[
                    self._id]['state'][-1] == ConversationHandler.END:
                # Message if want to complete questions once again
                update.message.reply_text('Wonna try it once again?',
                                          reply_markup=ReplyKeyboardMarkup(
                                              [['Yes'], ['No']],
                                              one_time_keyboard=True))
                return RETRY
            else:
                last_answered_line = self.get_last_answered(update, context)
                next_state = last_answered_line.get_next(update)
                context.user_data[self._id]['state'].append(next_state)
                database.update_dialog_status(
                    update.effective_user.id, self._id,
                    last_answered_line.get_answer_num(update))
                if last_answered_line.is_test_question:
                    self.update_test(line=last_answered_line,
                                     update=update,
                                     context=context)
                if last_answered_line.is_custom:
                    # update.message.reply_text('pls tell us what u want here')
                    return CUSTOM_CHOICE
                if next_state != ConversationHandler.END:
                    self.lines[next_state].send_line(update, context)
                    if self.lines[next_state].type == 'test_final':
                        result = self.finalize_test(next_state, context)
                        self.lines[result].send_line(update, context)
                        context.user_data[self._id]['state'].append(result)
                        return REGULAR_CHOICE

                    if self.lines[next_state].should_send_next:
                        self.lines[next_state + 1].send_line(update, context)
                        context.user_data[self._id]['state'].append(
                            next_state + 1)
                    return REGULAR_CHOICE
                else:
                    # write last message here
                    update.message.reply_text('thanks for ur info')
                    return ConversationHandler.END
        else:
            database.insert_user(update.effective_user.id)
            database.embed_user_dialog(update.effective_user.id, self._id)
            next_state = -1 if self.name == 'Вложить или накопить деньги' else 0
            state_dict = {'state': [next_state], 'test_val': 0}
            context.user_data[self._id] = state_dict
            self.lines[next_state].send_line(update)
            if self.lines[next_state].should_send_next:
                self.lines[next_state + 1].send_line(update, context)
                context.user_data[self._id]['state'].append(next_state + 1)
            return REGULAR_CHOICE
Пример #26
0
def test_get_all_lists(req_context):
    from database import get_all_users_lists, make_list, insert_user
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("My Title", "My description", user_id)
    make_list(*expected)
    lists = get_all_users_lists(user_id)
    assert len(lists) == 1
    for l in lists:
        assert expected[0] == l['title']
        assert expected[1] == l['description']
Пример #27
0
def test_make_list(req_context):
    from database import insert_user
    from database import make_list
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("My Title", "My description", user_id)
    make_list(*expected)
    rows = run_independent_query("SELECT * FROM lists")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #28
0
 def confirm_event(self):
     """
     Instantiates a user object and adds it to the database and then instantiates the main menu with the user
     :return: None
     """
     user = User(str(self.name.text()), float(self.weight.text()),
                 float(self.goal.text()), int(self.height.text()))
     database.insert_user(user)
     user = database.retrieve_user(user_id=1)
     self.master.create_main_menu(user)
     self.close_dialog()
Пример #29
0
def test_delete_list(req_context):
    from database import insert_user, make_list, insert_list_item
    from database import delete_list, get_all_users_lists
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    insert_list_item(list_id, "Do this")
    delete_list(list_id)
    lists = get_all_users_lists(user_id)
    assert len(lists) == 0
Пример #30
0
def test_update_list_title_test(req_context):
    from database import insert_user, make_list, update_list_title_text
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    expected = ("New Title", "New description")
    update_list_title_text(*expected, list_id=list_id)
    rows = run_independent_query("SELECT title, description FROM lists")
    for val in expected:
        assert val in rows[0]
Пример #31
0
def test_make_list(req_context):
    from database import insert_user
    from database import make_list
    insert_user("Test User", "pass", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    expected = ("My Title", "My description", user_id)
    make_list(*expected)
    rows = run_independent_query("SELECT * FROM lists")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #32
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    if request.method == 'POST':
        print(request.form)
        email = request.form['email']
        password = request.form['password1']
        if database.check_password_in_database(email):
            return ('You are already registered')
        else:
            database.insert_user(email, password, 'salt')
    return redirect(url_for('main'))
Пример #33
0
def test_get_all_list_users(req_context):
    from database import get_all_list_users, make_list, insert_user
    from database import add_list_user
    insert_user("Test User", "pass", "*****@*****.**")
    insert_user("Another User", "pass", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("My Title", "My description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    print list_id, user_id1, user_id2
    add_list_user(list_id, user_id2)
    actual = get_all_list_users(list_id)[0]['list_id']
    assert user_id2 == actual
Пример #34
0
def test_delete_list_user(req_context):
    from database import insert_user, make_list, add_list_user
    from database import delete_list_user, get_all_list_users
    insert_user("Test User", "password", "*****@*****.**")
    insert_user("Test User2", "password2", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("Title", "Description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    add_list_user(list_id, user_id2)
    delete_list_user(list_id, user_id2)
    list_users = get_all_list_users(list_id)
    assert len(list_users) == 0
Пример #35
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if db.user_exists(username):
            flash('The Username {} is Already Taken'.format(username))
            return redirect(url_for('register'))
        else:
            db.insert_user(username, password)
            return redirect(url_for('login'))
    else:
        args = {'active': 'register'}
        return render_template('register.html', args=args)
Пример #36
0
def test_delete_list_user(req_context):
    from database import insert_user, make_list, add_list_user
    from database import delete_list_user, get_all_list_users
    insert_user("Test User", "password", "*****@*****.**")
    insert_user("Test User2", "password2", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("Title", "Description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    add_list_user(list_id, user_id2)
    delete_list_user(list_id, user_id2)
    list_users = get_all_list_users(list_id)
    assert len(list_users) == 0
Пример #37
0
    def sing_up(self):
        username = self.root.get_screen("singupscreen").ids.username_text.text
        password = self.root.get_screen("singupscreen").ids.password_text.text
        email = self.root.get_screen("singupscreen").ids.email_text.text
        result = singup_test(email)

        if result == None and username != '' and password != '' and email != '':
            insert_user(username, email, password)
            set_status('False')
            self.reset_sing_up()
            MDApp.get_running_app().root.current = 'loginscreen'
        else:
            self.pop_up()
Пример #38
0
def test_get_all_list_users(req_context):
    from database import get_all_list_users, make_list, insert_user
    from database import add_list_user
    insert_user("Test User", "pass", "*****@*****.**")
    insert_user("Another User", "pass", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("My Title", "My description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    print list_id, user_id1, user_id2
    add_list_user(list_id, user_id2)
    actual = get_all_list_users(list_id)[0]['list_id']
    assert user_id2 == actual
Пример #39
0
def test_update_checkmark(req_context):
    from database import insert_user, make_list, insert_list_item
    from database import update_item_checkmark
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    insert_list_item(list_id, "Do this")
    # item_id is second result in query
    item_id = run_independent_query("SELECT * FROM list_items")[0][1]
    check_zero = run_independent_query("SELECT checked FROM list_items")[0][0]
    assert check_zero == 0
    update_item_checkmark(1, list_id, item_id)
    check_one = run_independent_query("SELECT checked FROM list_items")[0][0]
    assert check_one == 1
Пример #40
0
def test_update_checkmark(req_context):
    from database import insert_user, make_list, insert_list_item
    from database import update_item_checkmark
    insert_user("Test User", "password", "*****@*****.**")
    user_id = run_independent_query("SELECT user_id FROM users")[0][0]
    make_list("Title", "Description", user_id)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    insert_list_item(list_id, "Do this")
    # item_id is second result in query
    item_id = run_independent_query("SELECT * FROM list_items")[0][1]
    check_zero = run_independent_query("SELECT checked FROM list_items")[0][0]
    assert check_zero == 0
    update_item_checkmark(1, list_id, item_id)
    check_one = run_independent_query("SELECT checked FROM list_items")[0][0]
    assert check_one == 1
Пример #41
0
def mobile_registration_handler():
    body = request.get_json()
    double_name = body.get('doubleName').lower()
    sid = body.get('sid')
    email = body.get('email')
    public_key = body.get('public_key')

    if double_name == None or email == None or public_key == None or sid == None:
        return Response("Missing data", status=400)
    else:
        user = db.getUserByName(conn, double_name)
        if user is None:
            update_sql = "INSERT into users (double_name, sid, email, public_key) VALUES(?,?,?,?);"
            db.insert_user(conn, update_sql, double_name, sid, email,
                           public_key)
        return Response("Succes", status=200)
Пример #42
0
def test_add_list_user(req_context):
    from database import insert_user
    from database import make_list
    from database import add_list_user
    insert_user("Test User", "pass", "*****@*****.**")
    insert_user("Another User", "pass", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("My Title", "My description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    expected = (list_id, user_id2)
    add_list_user(*expected)
    rows = run_independent_query("SELECT * FROM list_users")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #43
0
def test_add_list_user(req_context):
    from database import insert_user
    from database import make_list
    from database import add_list_user
    insert_user("Test User", "pass", "*****@*****.**")
    insert_user("Another User", "pass", "*****@*****.**")
    user_id1 = run_independent_query("SELECT user_id FROM users")[0][0]
    user_id2 = run_independent_query("SELECT user_id FROM users")[1][0]
    make_list("My Title", "My description", user_id1)
    list_id = run_independent_query("SELECT * FROM lists")[0][0]
    expected = (list_id, user_id2)
    add_list_user(*expected)
    rows = run_independent_query("SELECT * FROM list_users")
    assert len(rows) == 1
    for val in expected:
        assert val in rows[0]
Пример #44
0
def start_command(bot, update):
    if update.message.chat.type == 'private':
        userid = update.message.chat_id
        username = update.message.from_user.username
        firstname = update.message.from_user.first_name

        if check_user_exists(userid):
            bot.sendMessage(chat_id=userid, text=config['en_gb']['greet_seen'],
                            reply_markup=build_button_list(days=True))

        else:
            bot.sendMessage(chat_id=userid, text=config['en_gb']['greet_notseen'],
                            reply_markup=build_button_list(days=True))
            insert_user(userid, username, firstname)

    else:
        bot.sendMessage(chat_id=update.message.chat_id, text=config['en_gb']['pm_only'])
Пример #45
0
def mobile_registration_handler():
    logger.debug("/mobile_registration_handler ")
    body = request.get_json()
    double_name = body.get("doubleName").lower()
    email = body.get("email").lower().strip()
    public_key = body.get("public_key")
    if double_name == None or email == None or public_key == None:
        return Response("Missing data", status=400)
    else:
        if len(double_name) > 55 and double_name.endswith(".3bot"):
            return Response(
                "doubleName exceeds length of 50 or does not contain .3bot",
                status=400)
        user = db.get_user_by_double_name(conn, double_name)
        if user is None:
            update_sql = "INSERT into users (double_name, sid, email, public_key, device_id) VALUES(?,?,?,?,?);"
            db.insert_user(conn, update_sql, double_name, "", email,
                           public_key, "")
        return Response("Succes", status=200)
Пример #46
0
def registration(): 
    if request.method =='GET':
        return render_template('registration.html')
    else:
        name= request.form['name'] 
        email = request.form['email']
        password = request.form['password']
        if (database.insert_user(name,email,password)):
            print("user inserted")
        return  render_template('login.html')
Пример #47
0
def oauth():
    global user
    url = request.url
    text = re.sub('.*\?', '', url)
    params = parser(text)
    user = OAuth1Session(CK, CS, params['oauth_token'],
                         params['oauth_verifier'])
    res = user.post('https://api.twitter.com/oauth/access_token', params)
    params = parser(res.text)
    AK, AS = params['oauth_token'], params['oauth_token_secret']
    id_ = params['user_id']

    user = OAuth1Session(CK, CS, AK, AS)

    if is_exist(id_):
        update_user(id_, AK, AS)
    else:
        insert_user(id_, AK, AS)

    return redirect(url_for('application'))
Пример #48
0
def search_suggested_users(db_con, rate_limit=twitter_settings.multiple_user_sugg_limit):
    logging.info("Getting suggested users")

    # define the query url to get the suggestion categories
    query_url = "https://api.twitter.com/1.1/users/suggestions.json"
    logging.debug("Twitter API call: {0}".format(query_url))
    json_data = twitterreq(query_url, "GET")

    # get the suggestion slugs (i.e. suggested categories)
    slugs = [d["slug"] for d in json_data]

    # get the users for each slug
    n_requests = 0
    for slug in slugs:
        # define the query url to get the users
        query_url = "https://api.twitter.com/1.1/users/suggestions/{0}.json".format(slug)
        logging.debug("Twitter API call: {0}".format(query_url))
        json_data = twitterreq(query_url, "GET")

        if "users" not in json_data:
            raise Exception("JSON data has no users: {0}".format(json_data))
        users = json_data["users"]

        for user in users:
            db.insert_user(db_con, user, slug)
            if "screen_name" in user and user["screen_name"]:
                print("{0}:{1}".format(user["screen_name"], slug))

        n_requests += 1
        if n_requests >= rate_limit:
                logging.info("Sleeping for 15 mins to avoid rate limiting")
                time.sleep(900)
                n_requests = 0

    logging.info("Results written to database")
    return slugs
Пример #49
0
    def sign_up_clicked(self):
        self.line_edits = []
        self.line_edits.append(self.lineEditPassword)
        self.line_edits.append(self.lineEditName)
        self.line_edits.append(self.lineEditLastName)
        self.line_edits.append(self.lineEditAge)
        self.line_edits.append(self.lineEditWeight)
        self.line_edits.append(self.lineEditUsername)
        self.line_edits.append(self.lineEditPassword)

        self.label_validation.setText("")
        for line_edit in self.line_edits:
            if line_edit.text() == "":
                self.label_validationSign.setText("All fields required.")
                return

        new_user = User()

        new_user.first_name = str(self.lineEditName.text())
        new_user.last_name = str(self.lineEditLastName.text())
        new_user.age = int(self.lineEditAge.text())
        new_user.weight = int(self.lineEditWeight.text())
        new_user.user_name = str(self.lineEditUsername.text())
        new_user.password = str(self.lineEditPassword.text())

        error = database.insert_user(new_user)

        if error:

            if isinstance(error, MySQLdb.IntegrityError):
                if "Duplicate entry" in error.args[1]:
                    #If we have a duplicate entry
                    self.label_validation.setText("Sorry that username is already taken.")
        else:
            #If we successfully signed up we should set a message on log in page
            self.stackedWidget.setCurrentIndex(0)
            self.label_validationSign.setText("Sign up SUCCESSFUL!")
Пример #50
0
Файл: user.py Проект: cydev/cyvk
 def save(self):
     database.insert_user(self.jid, None, self.token, None, False)
Пример #51
0
    print('  ~:$ python3 manage.py load_default')
    sys.exit(1)


if __name__ == '__main__':
    if len(sys.argv) == 2 and sys.argv[1] == 'load_default':
        connection = database.connect()
        for table_name in 'users', 'tasks':
            database.drop_table(connection, table_name)
            database.create_table(connection, table_name)
            database.load_default(connection, table_name)
        connection.close()
    elif len(sys.argv) == 2 and sys.argv[1] == 'getusers':
        connection = database.connect()
        for user, password in database.get_user_credentials(connection):
            print('user:password -> {0}:{1}'.format(user, password))
        connection.close()
    elif len(sys.argv) == 3 and sys.argv[1] == 'adduser':
        connection = database.connect()
        database.insert_user(connection, sys.argv[2])
        connection.close()
    elif len(sys.argv) == 3 and sys.argv[1] == 'userdel':
        connection = database.connect()
        database.delete_user(connection, sys.argv[2])
        connection.close()
    else:
        print_usage()
        sys.exit(1)