Exemplo n.º 1
0
def handleReview(asin, list_of_review_dicts, productapi, producttype):
    global i
    product_dict = dict()
    product_dict["comments"] = list()

    try:
        product_dict = add_amazon_info_to_dict(asin, product_dict)
    except AmazonInfoNotFoundError:
        print("Couldn't find amazon info for product", i, " skipping")
        return
    # add the ASIN to the dict
    product_dict["asin"] = asin
    product_dict["type"] = producttype

    product = queries.find_media_by_asin(asin)
    if product is None:
        queries.insert_media(product_dict["title"], product_dict["creator"], product_dict["description"], producttype, asin, int(time.time()))
    else:
        queries.clean_media(product.media_id)
        queries.update_media(product.media_id, int(time.time()))


    for review in list_of_review_dicts:
        comment_dict = dict()
        # if these dont exist in some of them, then so help me god
        comment_dict["rating"] = review["overall"]
        comment_dict["helpful"] = review["helpful"]
        comment_dict["unixtime"] = int(review["unixReviewTime"])
        comment_dict["text"] = review["reviewText"]
        product_dict["comments"].append(comment_dict)

    # now process this dict in comment_processing
    filename = product_dict["title"] + "$$$" + asin

    processed_dict_dict = dict()
    try:
        processed_dict = calculateVectorsForAllComments(product_dict, g)
    except NoEmotionsFoundError:
        # REMOVE the media from the table since we don't want it anymore
        queries.remove_media(asin)
        print("couldnt find any emotions for product: ", i, "Skipping")
        return
    #create the summary
    processed_dict["summary"] = html.unescape(return_summary(processed_dict))

    processed_json = json.dumps(processed_dict, indent=4)

    print ("Adding product with asin: ", asin, "to S3 ---", i)
    push_to_S3(filename, processed_json)
Exemplo n.º 2
0
    def setUpClass(self):
        """ inserts test data """

        queries.insert_media('Batman: The Return of the Force', 'Dario', \
                             'A really cool movie', 'Film', '0440419395', 11)