Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '%s"': 0.07; 'try:': 0.07; 'valueerror:': 0.07; 'python': 0.09; 'dvi': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'index': 0.13; 'dec': 0.15; '(empty': 0.16; 'anymore': 0.16; 'csv': 0.16; 'enough.': 0.16; 'error"': 0.16; 'indexerror:': 0.16; 'lcd': 0.16; 'match:': 0.16; 'row': 0.16; 'subject:compare': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'changes': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'script': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; "i'm": 0.29; 'normally': 0.30; 'speakers': 0.30; 'error': 0.30; 'print': 0.32; 'says': 0.33; 'code:': 0.33; 'guys': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'updated': 0.34; 'thanks': 0.34; 'false': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'stock': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'gives': 0.39; 'header:Received:5': 0.40; 'wide': 0.62; 'here': 0.65; 'total': 0.65; 'skip:m 50': 0.65; 'price': 0.66; 'products': 0.70; 'confusing': 0.84; 'reports:': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=t4nDYSAmh9nTu47ROrJPGDtKn+qYLFPytaoKKMa2Tvc=; b=dc6KAlSt4e/9aDR3LwGf4FNP8iSARTMfLohbpOLlLuFUiaWw3+sjSW/ZQhA87Rju1U YGi8RzuPPypr/6AqyHylmW3crNuwTQgVENnSWmLFAAALs8mBjkuDjhD/WRDIWwQcWzAh 7jR+40JVCDgJYKI73FP2/lwV4yjvLOO9Us+q+SCOWVUnwNHv202F3BUIoe84XQJRLd0y HE8Z5vpRKnpmNHSHGaJ71nVnVEILdBdFuGSaWDP1rTOw7grGumdxXBt5NvKbAnEWU4md 2pQt95Y52lZOSxcC0AES5zDzWeD+hZZqbh4dCbobSrnMBwko6hXnde5IqJ8UzQI72mrg nJNw== MIME-Version: 1.0 In-Reply-To: References: <50c01fe2$0$21853$c3e8da3$76491128@news.astraweb.com> Date: Thu, 6 Dec 2012 17:16:29 +0100 Subject: Re: Confused compare function :) From: Anatoli Hristov To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354810592 news.xs4all.nl 6856 [2001:888:2000:d::a6]:58357 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!gegeweb.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:34401 On Thu, Dec 6, 2012 at 3:22 PM, Anatoli Hristov wrote: > Guys I'm still confusing my script is working better, but not enough. > I did a logfile to see which products are not found anymore in the CSV > and I found some that are present but python says they are not ?? > > Here is the product in the CSV: > MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide > 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41;;;;;;;;; > > Here is what python reports: > e2208hds-b2, 721 not found > e2273hds-b1, 722 not found > e2274hds-b2, 723 not found > e2407hds-b1, 724 not found > > And here is my final code: ( I hope it look better now :) ) > > def Change_price(): # Changes the price in the DB if the price in the > CSV is changed > TotalUpdated = 0 # Counter for total updated > TotalSKUFound = 0 # Total SKU from the DB coresponds to the one in the CSV > TotalSKUinDB = 0 # Total SKU in the DB > for row in PRODUCTSDB: > TotalSKUinDB +=1 > db_sku = row["sku"].lower() > db_price = float(row["price"]) > found = False > try: > for x in pricelist: > try: > csv_price = x[6] > csv_price = csv_price.replace(",",".") > csv_price = float(csv_price) > csv_new_price = csv_price*1.10 > csv_sku = x[4].lower() > csv_stock = int(x[7]) # I used this as normally I > used stock in the condition > match = re.search(db_sku, csv_sku) > if len(db_sku) != 0 and match: > TotalSKUFound +=1 > if csv_new_price < db_price and csv_stock > 0: > print db_sku, csv_price, db_price, csv_new_price > Update_SQL(csv_new_price, db_sku) > TotalUpdated += 1 > found = True > > except IndexError: # I have a lot of index error in > the CSV (empty fields) and the loop gives "index error" I don't care > about them > pass > except ValueError: > pass > except TypeError: > pass > except IndexError: > pass > if not found: WriteLog(db_sku, db_sku,) > TotalNotFound = TotalSKUinDB - TotalSKUFound > print "Total SKU in the DB %s" % TotalSKUinDB > print "Total SKU coresponds to the DB and CSV %s" % TotalSKUFound > print "Total updated: %s" % TotalUpdated > print"Total not found with in the distributor: %s" % TotalNotFound No one have an idea ? Thanks