Ejemplo n.º 1
0
def index(request):
    if request.method == "POST":
        form = InputForm(request.POST)
        # return HttpResponse(form.cleaned_data)
        if form.is_valid():
            zipcode1 = form.cleaned_data["zipcode1"]
            zipcode2 = form.cleaned_data["zipcode2"]
            weight = form.cleaned_data["weight"]
            date1 = form.cleaned_data["date1"]
            carrier = form.cleaned_data["carrier"]
            if carrier == "UPS":
                scraper = UpsScraper()
                # print scraper.get_availability('AEM2238-4')
                results = scraper.get_estimate(zipcode1, zipcode2, weight, date1)
                if results == "":
                    context = {"info": "The UPS website is down. Please try again later."}
                    return render(request, "shipping/index.html", context)

            if carrier == "IDC":
                # scraper = IdcScraper()
                # results = scraper.get_estimate(zipcode1, zipcode2, weight)
                context = {"info": "The IDC_USA service is not available."}
                return render(request, "shipping/index.html", context)

            context = {
                "results": results,
                "info": "Done. These are all the results.",
                "zipcode1": zipcode1,
                "zipcode2": zipcode2,
                "weight": weight,
                "date1": date1.strftime("%m/%d/%Y"),
            }
            return render(request, "shipping/index.html", context)

        else:
            context = {"info": "The data introduced is not valid."}
            return render(request, "shipping/index.html", context)
    else:
        form = InputForm()
        context = {"results": ""}
        return render(request, "shipping/index.html", context)
Ejemplo n.º 2
0
def estimate(request):
    today = datetime.today()
    # date = today.strftime('%m/%d/%Y')
    if request.method == "GET":
        zipcode1 = request.GET.get("zipcode1", "")
        zipcode2 = request.GET.get("zipcode2", "")
        weight = request.GET.get("weight", 0)
        if float(weight) == 0:
            weight = 0.9

        if float(weight) > 150:
            scraper = UpsScraper()
            ups_result = scraper.get_freight_estimate(zipcode1, zipcode2, weight)
            scraper = IdcScraper()
            idc_result = scraper.get_freight(zipcode1, zipcode2, weight, today)
            output = "UPS Next Day Air:<br>$%s<br>FedEx Freight:<br>$%s" % (ups_result, idc_result)
        else:
            scraper = UpsScraper()
            ups_result = scraper.get_ups_ground(zipcode1, zipcode2, weight, today)
            scraper = IdcScraper()
            idc_result = scraper.get_freight(zipcode1, zipcode2, weight, today)
            output = "UPS Ground:<br>$%s<br>FedEx Freight:<br>$%s" % (ups_result, idc_result)
        return HttpResponse(output)