Exemplo n.º 1
0
async def start_command_handler(message: types.Message):
    db_utils.add_user(message.from_user)
    await bot.send_message(chat_id=message.chat.id,
                           text=config.start_message,
                           disable_web_page_preview=True,
                           parse_mode=types.ParseMode.MARKDOWN,
                           reply_markup=inline_keyboards.start_keyboard())
Exemplo n.º 2
0
async def search_handler(message):
    search_results = await deezer_api.search(q=message.text)
    if not len(search_results):
        return await bot.send_message(message.chat.id, 'Nothing was found')

    await bot.send_message(
        chat_id=message.chat.id,
        text=message.text + ':',
        reply_markup=inline_keyboards.search_results_keyboard(
            search_results, 1))
    db_utils.add_user(message.from_user)
Exemplo n.º 3
0
    def submit(self):

        if self.namee.text != "" and self.email.text != "" and self.email.text.count(
                "@") == 1 and self.email.text.count(".") > 0:
            if self.password != "":
                db_u.add_user(self.email.text, self.password.text,
                              self.namee.text)
                sm.current = "login"
            else:
                erro_form('senha')
        else:
            erro_form('email')
Exemplo n.º 4
0
async def search_handler(message):
    search_results = await deezer_api.search(message.text)
    if not search_results:
        search_results = await soundcloud_api.search(message.text)
        return await bot.send_message(
            chat_id=message.chat.id,
            text=message.text + ':',
            reply_markup=sc_keyboards.search_results_keyboard(
                search_results, 1, 7),
            reply_to_message_id=message.message_id)
    else:
        await bot.send_message(
            chat_id=message.chat.id,
            text=message.text + ':',
            reply_markup=dz_keyboards.search_results_keyboard(
                search_results, 1, 7),
            reply_to_message_id=message.message_id)
    db_utils.add_user(message.from_user)
Exemplo n.º 5
0
def do_sign_in():
    # This is meant to be reached from AJAX request.
    # We return a JSON response that will be used by
    # The JS code making the request.
    if (request.form['signin_request_token'] !=
            login_session['signin_request_token']):
        return response.error('Invalid token.')

    g_id_token = request.form['id_token']
    try:
        idinfo = id_token.verify_oauth2_token(g_id_token, requests.Request(),
                                              CLIENT_ID)
        if (idinfo['iss']
                not in ['accounts.google.com', 'https://accounts.google.com']):
            raise ValueError('Wrong issuer.')

        if idinfo['aud'] != CLIENT_ID:
            raise ValueError('Invalid client id.')

    except ValueError:
        return response.error('Could not sign in')

    user_id = idinfo['sub']

    stored_id_token = login_session.get('id_token')
    stored_user_id = login_session.get('user_id')

    user = db_utils.get_user(user_id)
    if user is None:
        # Add user to database if id does not exist.
        db_utils.add_user(user_id, idinfo['email'], idinfo['name'])

    if stored_id_token is not None and stored_user_id == user_id:
        return response.success()

    # Store the access token in the session for later use.
    login_session['id_token'] = g_id_token
    login_session['user_id'] = user_id
    login_session['name'] = idinfo['name']
    login_session['email'] = idinfo['email']
    login_session['picture'] = idinfo['picture']
    return response.success()
Exemplo n.º 6
0
def sign_up(request):
    if request.POST:

        email = request.POST['email']
        username = request.POST['username']
        password = request.POST['password']
        password_confirm = request.POST['password_confirm']

        msg = ''
        if not utils.validate_email(email):
            msg = u'邮箱格式不正确'
            return JsonResponse({'success': False, 'msg': msg})

        if password != password_confirm:
            msg = u'两次密码输入不一致'
            return JsonResponse({'success': False, 'msg': msg})

        if db_utils.email_registered(email):
            msg = u'该邮箱已被注册'
            return JsonResponse({'success': False, 'msg': msg})

        if db_utils.name_used(username):
            msg = u'该昵称已被使用'
            return JsonResponse({'success': False, 'msg': msg})

        try:
            db_utils.add_user(email, username, password)
            msg = u'注册成功'
        except Exception as e:
            msg = u'注册失败'

        user = authenticate(username=email, password=password)
        if user and user.is_active:
            login(request, user)

        return JsonResponse({'success': True, 'msg': msg, 'url': '/'})
    else:
        return render(request, "sign_up.html")
Exemplo n.º 7
0
async def track_handler(message):
    track = await deezer_api.gettrack(message.text.split('/')[-1])
    if utils.already_downloading(track.id):
        return
    await methods.send_track(track, message.chat)
    db_utils.add_user(message.from_user)
Exemplo n.º 8
0
async def track_handler(message, track_id):
    track = await deezer_api.gettrack(track_id)
    if utils.already_downloading(track.id):
        return
    await methods.send_track(message.chat.id, track)
    db_utils.add_user(message.from_user)
Exemplo n.º 9
0
import db_utils

users = [('Gautam', '+19084204948'), ('Shyam', '+19083589340'),
         ('Shravan', '+19083589574')]
chores = ['Dishes', 'Cleaning', 'Laundry']
instances = [(1, 1, 0), (1, 2, 0), (2, 1, 0), (2, 3, 0), (1, 1, 14),
             (2, 3, 14)]

for user in users:
    db_utils.add_user(user[0], user[1])
print "users table:"
print db_utils.get_users()

for chore in chores:
    db_utils.add_chore(chore)
print "chores table:"
print db_utils.get_chores()

for instance in instances:
    db_utils.add_instance(instance[0], instance[1], instance[2])
print "instances table:"
print db_utils.get_instances()
Exemplo n.º 10
0
def main():
    if PARAMS['command'] is None:
        utils.print_message("Error: Empty command. Exit.")
        return

    login, password = utils.read_login_pwd()
    insta = instagram.Instagram(login, password)

    #statistic
    inserted_posts = 0
    successfuly_posted = 0
    new_accounts = 0
    posted_comments = 0

    utils.print_message("Command: '{}'".format(PARAMS['command']))
    if PARAMS['command'].lower() == "insert_posts":
        for post in PARAMS["posts"]:
            utils.print_message("Inserted {} of {} rows".format(
                inserted_posts, len(PARAMS["posts"])),
                                2,
                                end="\r")
            try:
                inserted_posts += 1 if db_utils.add_post(post[0],
                                                         post[1]) else 0
            except:
                utils.print_message(traceback.format_exc())
                pass
        utils.print_message("Inserted rows {}. In control file {} {}".format(
            inserted_posts, len(PARAMS["posts"]), " " * 20))
        db_utils.commit()
    elif PARAMS['command'].lower() == "posting":
        utils.print_message("Processing...")
        posts = db_utils.get_not_posted_posts(PARAMS["posts_count"])
        for post_num, post in enumerate(posts):
            id, fname, descr = post
            try:
                if insta.post_photo(fname, descr):
                    db_utils.set_posted(id)
                    successfuly_posted += 1
                if post_num < len(posts) - 1:
                    for seconds in range(PARAMS['timeout']):
                        utils.print_message(
                            "Sleep {} seconds...".format(PARAMS['timeout'] -
                                                         seconds),
                            2,
                            end="\r")
                        time.sleep(1)
                utils.print_message(" " * 25, 2, end="\r")
            except:
                utils.print_message(traceback.format_exc())
                pass
        db_utils.commit()
        utils.print_message("Total new photos posted: {} {}".format(
            successfuly_posted, " " * 25))
    elif PARAMS['command'].lower() == "username2id":
        utils.print_message("Processing...")
        for user_num, username in enumerate(PARAMS["usernames"]):
            utils.print_message(
                "Get info about account #{} '{}' ({} total)...".format(
                    user_num + 1, username, len(PARAMS["usernames"])),
                2,
                end="\r")
            try:
                user_id = insta.API.username_info(username)["user"]["pk"]
                utils.print_message(
                    "Insert new account '{}' in database... {}".format(
                        username, " " * 10),
                    2,
                    end="\r")
                new_accounts += 1 if db_utils.add_user(username,
                                                       user_id) else 0
                utils.print_message(
                    "Info about account '{}' inserted in database{}".format(
                        username, " " * 25), 2)
            except:
                utils.print_message(traceback.format_exc())
                utils.print_message(
                    "Hasn't info about account '{}' {}".format(
                        username, " " * 25), 2)
        utils.print_message("Inserted new accounts in database: {} {}".format(
            new_accounts, " " * 25))
        db_utils.commit()
    elif PARAMS['command'].lower() == "spam":
        if PARAMS['mode'].lower() in ("users", "all"):
            utils.print_message("Spam comments to users posts...")
            posted_comments += insta.spam_in_users_comments([
                info[2]
                for info in db_utils.select_users(PARAMS['users_count'])
            ], PARAMS['text'], PARAMS['comments_count'])
        if PARAMS['mode'].lower() in ("feedline", "all"):
            utils.print_message("Spam comments to feedline posts...")
            posted_comments += insta.spam_in_timeline_comments(
                PARAMS['text'], PARAMS['comments_count'])
        utils.print_message("Posted spam comments: {} {}".format(
            posted_comments, " " * 25))
Exemplo n.º 11
0
def user_add(name):
    data = {'name': name}
    result = add_user(data)
    return result
Exemplo n.º 12
0
def add_user(name):
    number = request.values.get('From', None)
    db_utils.add_user(name, number)
    resp = MessagingResponse()
    resp.message("added user {0} with number {1}".format(name, number))
    return str(resp)