split xml file into products

<code>
f=open(filename,"a+")
            while(True):
                line_feed=f.readline()
                start_line="<?xml version="1.0" encoding="utf-8" ?><root>"
                end_line="<metadata><date>Tue Sep 27 02:19:53 PDT 2011</date><dump_type>full_set</dump_type><product_count>98968</product_count><tag_count>966399</tag_count></metadata>"
                content=start_line
                if(line_feed):
                    if(line_feed.find("<product product_number=")>-1):
                        content+=line_feed
                        if(line_feed.find("</product>")):
                            content+=end_line
                            ff=open("temp.importer","w")
                            ff.write(content)
                            try:
                                import_nextag_products.import_products(temp.importer, steps_flags)
                            except Exception, exception:
                                log.exception('%s: %s, options: %s', exception.__class__.__name__, exception, self.options)
                                raise
                            finally:
                                if import_nextag_products is not None:
                                    log.info("Done. File: %s, Total: %s, Processed: %d, Skipped: %s, New products: %s, Updated: %s.  Options: %s",
                                             filename,
                                             import_nextag_products.total_processed_count + import_nextag_products.total_skipped_count,
                                             import_nextag_products.total_processed_count,
                                             import_nextag_products.total_skipped_count,
                                             import_nextag_products.new_product_count,
                                             import_nextag_products.product_update_count,
                                             self.options)
                                else:
                                    log.info('Done.  Options: %s', self.options)
                else:
                    log.info("File reading complete")
                    break

</code>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: