Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34391
| References | (2 earlier) <k9p32p$nek$1@dont-email.me> <50c01fe2$0$21853$c3e8da3$76491128@news.astraweb.com> <mailman.549.1354783761.29569.python-list@python.org> <k9q6s4$os9$1@r03.glglgl.gl> <CAPTjJmqhY2Nxcf-MqCZ2Z8EXvfAtDASt_oPVg+=WcwVFwBBqEQ@mail.gmail.com> |
|---|---|
| Date | 2012-12-06 15:22 +0100 |
| Subject | Re: Confused compare function :) |
| From | Anatoli Hristov <tolidtm@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.559.1354803788.29569.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Confused compare function :) Bruno Dupuis <python.ml.bruno.dupuis@lisael.org> - 2012-12-06 01:19 +0100
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-06 00:42 +0000
Re: Confused compare function :) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-06 13:41 -0500
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 19:55 +0100
Re: Confused compare function :) Rotwang <sg552@hotmail.co.uk> - 2012-12-06 03:22 +0000
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-06 04:32 +0000
Re: Confused compare function :) Bruno Dupuis <python.ml.bruno.dupuis@lisael.org> - 2012-12-06 09:49 +0100
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-06 11:47 +0000
Re: Confused compare function :) peter <pjmakey2@gmail.com> - 2012-12-06 08:55 -0300
Re: Confused compare function :) Hans Mulder <hansmu@xs4all.nl> - 2012-12-06 14:32 +0100
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-07 00:47 +1100
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-06 23:14 +1100
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-07 22:16 +0000
Re: Confused compare function :) Terry Reedy <tjreedy@udel.edu> - 2012-12-08 02:01 -0500
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-08 18:17 +1100
Re: Confused compare function :) MRAB <python@mrabarnett.plus.com> - 2012-12-08 17:50 +0000
Re: Confused compare function :) Ramchandra Apte <maniandram01@gmail.com> - 2012-12-08 19:07 -0800
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-09 14:22 +1100
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-09 07:39 +0000
Re: Confused compare function :) Ramchandra Apte <maniandram01@gmail.com> - 2012-12-08 19:07 -0800
Re: Confused compare function :) Neil Cerutti <neilc@norwich.edu> - 2012-12-06 13:51 +0000
Re: Confused compare function :) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-07 02:55 +0000
Re: Confused compare function :) Neil Cerutti <neilc@norwich.edu> - 2012-12-07 16:40 +0000
Re: Confused compare function :) Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-12-06 14:33 +0100
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-07 00:58 +1100
Re: Confused compare function :) Hans Mulder <hansmu@xs4all.nl> - 2012-12-06 15:21 +0100
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-07 01:28 +1100
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 15:22 +0100
Re: Confused compare function :) Dave Angel <d@davea.name> - 2012-12-06 09:40 -0500
Re: Confused compare function :) peter <pjmakey2@gmail.com> - 2012-12-06 11:46 -0300
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 17:16 +0100
Re: Confused compare function :) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-12-06 16:52 +0000
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 18:08 +0100
Re: Confused compare function :) MRAB <python@mrabarnett.plus.com> - 2012-12-06 17:10 +0000
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 18:31 +0100
Re: Confused compare function :) MRAB <python@mrabarnett.plus.com> - 2012-12-06 17:52 +0000
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-06 19:25 +0100
Re: Confused compare function :) Anatoli Hristov <tolidtm@gmail.com> - 2012-12-07 14:36 +0100
Re: Confused compare function :) Rotwang <sg552@hotmail.co.uk> - 2012-12-06 19:24 +0000
Re: Confused compare function :) Chris Angelico <rosuav@gmail.com> - 2012-12-06 20:34 +1100
Re: Confused compare function :) Rotwang <sg552@hotmail.co.uk> - 2012-12-06 19:25 +0000
csiph-web