Пример #1
0
def claim(payload):
    s = security.get_serializer()
    try:
        (identifier, email, price) = s.loads(payload)
        print (identifier, email, price)
    except BadSignature:
        abort(404)
    Watch.objects(identifier=identifier).filter(watchers__email=email).update_one(add_to_set__watchers__S__claims=Price(price=price))
    return redirect('https://www.alaskaair.com/booking/ssl/garr/GuaranteedAirfare.aspx', code=302)
Пример #2
0
def unwatch_from_email(payload):
    from www.helpers import redirect_url
    s = security.get_serializer()
    try:
        (identifier, email) = s.loads(payload)
        print (identifier, email)
    except BadSignature:
        abort(404)
    Watch.objects(identifier=identifier, watchers__email=email).update_one(set__watchers__S__watching=False)
    flash("You have been unsubscribed from any future price alerts on that flight.", 'warning')
    return redirect(redirect_url())
Пример #3
0
def watching():
    watched = Watch.objects(watchers__email=g.user.email).no_dereference()
    claims, refunded, num_watching = 0, 0, 0
    itineraries = []
    for watch in watched:
        itinerary = Itinerary().from_identifier(watch.identifier)
        itinerary.price = watch.prices[-1].price
        for watcher in watch.watchers:
            if watcher.email == g.user.email:
                itinerary.claims = watcher.claims
                itinerary.paid = watcher.reservation['paid']
                itinerary.watching = watcher.watching
                if (itinerary.watching):
                    num_watching += 1
                claims += len(watcher.claims)
                if len(watcher.claims):
                    refunded += float(watcher.reservation['paid']) - \
                                float(watcher.claims[-1]['price'])
                    itinerary.refunded = refunded
                break
        itineraries.append(itinerary)                
    context = dict(
        user = g.user,
        claims = claims,
        refunded = refunded,
        itineraries = itineraries,
        num_watching = num_watching,
        watching = watched
    )
    return render_template('users/watching.html', **context)
Пример #4
0
def watch():
    response = 'failed'
    if g.user:
        # setup document
        identifier = request.form.get('id')
        search_params = security.json_decrypt(request.form.get('search'))
        price = Price(price=request.form.get('price'))
        watcher = Watcher(
            email = g.user.email,
            watching = True,
            reservation = dict(
                code = request.form.get('code'),
                name = request.form.get('name'),
                paid = request.form.get('paid')
                ),
            #claims = [price] if request.form.get('claim') else []
            )
        #watch.update_one(add_to_set__watchers__S__claims=Price(price=price))
        # create or update document
        watch = Watch.objects(identifier=identifier).first()
        if watch:
            #Watch.objects(identifier=identifier).filter(watchers__email=email).update_one(add_to_set__watchers__S__claims=Price(price=price))
            # inefficient way to check if user previously unwatched
            # really shouldn't do it this way
            rewatch = Watch.objects(identifier=identifier, watchers__email=g.user.email).update_one(set__watchers__S__watching=True)
            if not rewatch:
                watch.update(add_to_set__prices=price, add_to_set__watchers=watcher)
        else:
            watch = Watch(
                expires = datetime.datetime.strptime(search_params.get('DepartureDate1'),'%m/%d/%Y'),
                identifier = request.form.get('id'),
                prices = [price],
                search_params = search_params,
                watchers = [watcher]
                )
            watch.save()
        print(request.form)
        if request.form.get('claim') == 'true':
            Watch.objects(identifier=identifier).filter(watchers__email=g.user.email).update_one(add_to_set__watchers__S__claims=price)
        # email user    
        email = g.user.email
        itinerary = alaskaUtils.itinerary_from_identifier(request.form['id'])
        body = mail.watching_template(request, itinerary, g.user.email)
        mail.send_email(g.user.email, 'Fare Alert Added', body)   
        response = 'success'
    return jsonify(status=response)    
Пример #5
0
 def crawl(self):
     print 'crawl init'
     with self.app.app_context():
         docs = Watch.objects(expires__gt=datetime.datetime.utcnow())
         print 'found %i docs' % len(docs)
         try:
             for doc in docs:
                 self.fetch(doc)
         except Exception as e:
             print e
Пример #6
0
def unwatch():
    response = 'failed'
    if g.user:
        # setup document
        identifier = request.form.get('id')
        # create or update document
        doc = Watch.objects(identifier=identifier, watchers__email=g.user.email).update_one(set__watchers__S__watching=False)
        response = 'success' if doc else 'error'
        # email user    
        email = g.user.email
        itinerary = alaskaUtils.itinerary_from_identifier(identifier)
        body = mail.watching_template(request, itinerary, email)
        #mail.send_email(g.user.email, 'Fare Alert Removed', body)   
    return jsonify(status=response)