Exemple #1
0
 def test_generate_output_for_3_listings_being2_for_one_product(self):
   reader = FileReader()
   search = MatchSearch()
   products = reader.read_products('products.txt')
   listings = self.listings([{"title":"Canon PowerShot SX130IS 12.1 MP Digital Camera with 12x Wide Angle Optical Image Stabilized Zoom with 3.0-Inch LCD","manufacturer":"Canon Canada","currency":"CAD","price":"209.00"},{"title":"Canon PowerShot SX130IS 12.1 MP Digital Camera with 12x Wide Angle Optical Image Stabilized Zoom with 3.0-Inch LCD","manufacturer":"Canon Canada","currency":"CAD","price":"199.96"}, {"title":"Canon PowerShot D10 12.1 MP Waterproof Digital Camera with 3x Optical Image Stabilized Zoom and 2.5-inch LCD (Blue/Silver)","manufacturer":"Canon Canada","currency":"CAD","price":"306.24"}])
   expected_output = json.loads('{"Canon_PowerShot_SX130_IS" :[{"title":"Canon PowerShot SX130IS 12.1 MP Digital Camera with 12x Wide Angle Optical Image Stabilized Zoom with 3.0-Inch LCD","manufacturer":"Canon Canada","currency":"CAD","price":"209.00"},{"title":"Canon PowerShot SX130IS 12.1 MP Digital Camera with 12x Wide Angle Optical Image Stabilized Zoom with 3.0-Inch LCD","manufacturer":"Canon Canada","currency":"CAD","price":"199.96"}],"Canon_PowerShot_D10": [{"title":"Canon PowerShot D10 12.1 MP Waterproof Digital Camera with 3x Optical Image Stabilized Zoom and 2.5-inch LCD (Blue/Silver)","manufacturer":"Canon Canada","currency":"CAD","price":"306.24"}]}')
   result = search.match_listings(listings, products)
   
   self.assertEqual(expected_output, result)
Exemple #2
0
import os
import json
from challenge import FileReader, Product, Listing, MatchSearch
import challenge

reader = FileReader()
search = MatchSearch()
products = reader.read_products("products.txt")
listings = reader.read_listings("listings.txt")
listings = listings[0:1000]

result = search.match_listings(listings, products, debug=lambda c: print(c))

f = open("output.txt", "w")

key_list = list(result.keys())
key_list = sorted(key_list, key=lambda s: s.lower())
for key in key_list:
    f.write(json.dumps({"product_name": key, "listings": result[key]}))
    f.write("\n")

f.close()

print("non matches: " + str(len(search.non_matches)))

f = open("output_non_matches.txt", "w")

for non_match in search.non_matches:
    f.write(json.dumps(non_match.dict_without_tags()))
    f.write("\n")