Example #1
0
def get_product(product_id):
    products = product.get_products()
    if product_id in products.keys():
        item = product.get_products()[product_id]
        ensure_vote_stats(item)
        return jsonify(item)
    abort(404)
Example #2
0
def update_product(product_id, rank):
    if not rank.isdigit():
        abort(401)
    elif int(rank) > 5 or int(rank) < 1:
        abort(400)
    products = product.get_products()
    if product_id in products.keys():
        item = product.get_products()[product_id]
        ensure_vote_stats(item)
        item['votes_by_star'][int(rank) - 1] += 1
        new_rank = WeightedAverage(float(item['rating']), int(item['votes'])).add_value(int(rank))
        item['rating'] = new_rank.rank
        item['votes'] = new_rank.count
        return jsonify(item)
    abort(404)
Example #3
0
def callback():
    URL = request.url_root.strip("/")
    print(URL)
    facebook = requests_oauthlib.OAuth2Session(FB_CLIENT_ID,
                                               scope=FB_SCOPE,
                                               redirect_uri=URL +
                                               "/fb-callback")

    facebook = facebook_compliance_fix(facebook)

    facebook.fetch_token(
        FB_TOKEN_URL,
        client_secret=FB_CLIENT_SECRET,
        authorization_response=flask.request.url,
    )

    facebook_user_data = facebook.get(
        "https://graph.facebook.com/me?fields=id,name,email,picture{url}"
    ).json()

    email = facebook_user_data["email"]
    name = facebook_user_data["name"]
    picture_url = facebook_user_data.get("picture", {}).get("data",
                                                            {}).get("url")
    result = get_products()
    session["USERNAME"] = email
    return render_template('index.html', data=result, user_data=email)
Example #4
0
def login():
    if request.method == 'POST':
        email = request.form.get('email')
        password = request.form.get('password')
        print(email)
        print(password)
        try:
            user = UsersModel.query.filter_by(email=email).first()
            hashedpasswd = user.password  #hashedpassword
            passwd = str.encode(password)
            check = bcrypt.checkpw(passwd, hashedpasswd.encode("utf-8"))
            if check:
                print("The passwords match.")
                print(user.email)
                result = get_products()
                session["USERNAME"] = user.email
                user_email = session.get("USERNAME")
                return render_template('index.html',
                                       data=result,
                                       user_data=user.email)
            else:
                print("The passwords do not match.")
        except:
            return render_template('login.html')
    return render_template('login.html')
Example #5
0
def socialogin():
    data = json.loads(request.data)
    if request.method == 'POST':
        print(data)
        result = get_products()
        return render_template('index.html', data=result)

    return render_template('index.html')
Example #6
0
def main() -> None:
    while True:
        try:
            products = get_products(proxies[random.randrange(
                0,
                len(proxies) - 1)])
        except TimeoutError:
            logger.error("Page could not be loaded")
            continue

        logger.info(f"Retrieved {len(products)} products")

        for product in products:
            if candidate(product):
                price_notification(**product)

        duration = random.randrange(CYCLE_RANGE[0], CYCLE_RANGE[1])
        logger.info(f"Cycle done; sleep for {duration} seconds")
        time.sleep(duration)
Example #7
0
def main(email, number):
    with requests.Session() as s:
        # get products
        response = s.get(urljoin(URL, '/nl/en/prepaid-beltegoed-opwaarderen'))
        products = get_products(response.content)

        # select product
        product = select_product(products)
        buynow = s.post(urljoin(URL, product.form.action), data=product.form.data)
        form = Form.from_id(buynow.content, 'buyNowAutoSubmit')
        topup_login = s.post(urljoin(URL, form.action), data=form.data,
                             allow_redirects=True)

        # Authorize
        guest_form = Form.from_id(topup_login.content, 'lebara-form')
        guest_form.data.update(email=email, msisdn=number, msisdnCheck=number)
        auth_response = s.post(urljoin(URL, guest_form.action), data=guest_form.data)
        auth_form = Form.from_id(auth_response.content, 'lebara-form')
        if auth_form and auth_form.errors:
            print('\n'.join(auth_form.errors))
            return

        # select payment method
        response = s.get(urljoin(URL, '/nl/en/cart/checkout'), allow_redirects=True)
        form = Form.from_id(response.content, PAY_FORM_ID)
        for field in form.fields:
            if field.name == 'select':
                selection = select_bank(field.find_all('option')[1:])
                value = field.find('option', text=selection)['value']
                form.data[field['name']] = value

        # checkout to get the form to pay
        process_response = s.post(urljoin(URL, form.action), data=form.data)
        form = Form.from_id(process_response.content, PAY_FORM_ID)
        del form.data['CSRFToken']
        response = s.post(form.action, data=form.data, allow_redirects=True)

        webbrowser.open_new_tab(response.url)
Example #8
0
def products():
    return render_template("products.html",
                           products=get_products(),
                           active='products')
Example #9
0
def main():
    result = get_products()
    if 'USERNAME' in session:
        user_email = session.get("USERNAME")
        return render_template('index.html', data=result, user_data=user_email)
    return render_template('index.html', data=result)
Example #10
0
def fill_in_vote_stats():
    products = product.get_products()
    for item in products.values():
        ensure_vote_stats(item)
    return jsonify(products)
Example #11
0
def get_products():
    return jsonify(product.get_products())
Example #12
0
def home_page():
    products_dict = product.get_products()
    return render_template('snacks.html', pageType='products', products=(OrderedDict(sorted(products_dict.items(), key=lambda x: -x[1]['rating']))))
Example #13
0
def logout():
    session.pop("USERNAME")
    result = get_products()
    return render_template('index.html', data=result)