Beispiel #1
0
def products_get(tiids_string,
                 format="json",
                 most_recent_metric_date=None,
                 most_recent_diff_metric_date=None):
    tiids = tiids_string.split(",")
    override_export_clean = (format == "csv")
    cleaned_items_dict = cleaned_items(tiids, myredis, override_export_clean,
                                       most_recent_metric_date,
                                       most_recent_diff_metric_date)

    response_code = 200
    if not collection.is_all_done(tiids, myredis):
        response_code = 210  # update is not complete yet

    if format == "csv":
        csv = collection.make_csv_stream(cleaned_items_dict.values())
        resp = make_response(csv, response_code)
        resp.mimetype = "text/csv;charset=UTF-8"
        resp.headers.add("Content-Encoding", "UTF-8")
    else:
        resp = make_response(
            json.dumps({"products": cleaned_items_dict},
                       sort_keys=True,
                       indent=4), response_code)

    return resp
Beispiel #2
0
def single_product_get(tiid):
    cleaned_items_dict = cleaned_items([tiid], myredis)
    try:
        single_item = cleaned_items_dict[tiid]
    except TypeError:
        abort_custom(404, "No product found with that tiid")

    response_code = 200
    if not collection.is_all_done([tiid], myredis):
        response_code = 210 # update is not complete yet

    resp = make_response(json.dumps(single_item, sort_keys=True, indent=4),
                         response_code)

    return resp
Beispiel #3
0
def single_product_get(tiid):
    cleaned_items_dict = cleaned_items([tiid], myredis)
    try:
        single_item = cleaned_items_dict[tiid]
    except TypeError:
        abort_custom(404, "No product found with that tiid")

    response_code = 200
    if not collection.is_all_done([tiid], myredis):
        response_code = 210  # update is not complete yet

    resp = make_response(json.dumps(single_item, sort_keys=True, indent=4),
                         response_code)

    return resp
Beispiel #4
0
def products_get(tiids_string, format="json", most_recent_metric_date=None, most_recent_diff_metric_date=None):
    tiids = tiids_string.split(",")
    override_export_clean = (format=="csv")
    cleaned_items_dict = cleaned_items(tiids, myredis, override_export_clean, most_recent_metric_date, most_recent_diff_metric_date)

    response_code = 200
    if not collection.is_all_done(tiids, myredis):
        response_code = 210 # update is not complete yet

    if format == "csv":
        csv = collection.make_csv_stream(cleaned_items_dict.values())
        resp = make_response(csv, response_code)
        resp.mimetype = "text/csv;charset=UTF-8"
        resp.headers.add("Content-Encoding", "UTF-8")
    else:
        resp = make_response(json.dumps({"products": cleaned_items_dict}, sort_keys=True, indent=4),
                             response_code)

    return resp