コード例 #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)
コード例 #2
0
ファイル: test.py プロジェクト: CatalystOfNostalgia/hoot
    def test_updating_media(self):
        """ Tests updating media and media emotions """

        bat = queries.find_media_by_asin('0440419395')

        # testing updating the emotions
        queries.insert_media_emotion(bat.media_id, 'cool')
        queries.insert_media_emotion(bat.media_id, 'dark')

        emotions = queries.find_emotions_for_media(bat.media_id)

        self.assertTrue('dark' in emotions, \
                        "Didn't find all emotions for media")
        self.assertTrue('cool' in emotions, \
                        "Didn't find all emotions for media")

        # test updating the last_updated column
        queries.update_media(bat.media_id, 20)

        self.assertEqual(bat.last_updated, 20, \
                         'Did not updated date properly')