Exemplo n.º 1
0
    def test_clean(self):
        """ Tests cleaning the database of comments and emotions """

        bat = queries.find_media_by_asin('0440419395')
        queries.insert_comment(bat.media_id, 11, 7, 0.9, 0.4, -0.5, 0.6, 0.3)

        queries.clean_media(bat.media_id)

        comments = queries.find_comments_for_media(bat.media_id)
        emotions = queries.find_emotions_for_media(bat.media_id)

        self.assertEqual(len(comments), 0)
        self.assertEqual(len(emotions), 0)
Exemplo n.º 2
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)