Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- # coding: utf8
- import urllib as url
- from lxml import etree
- import psycopg2
- import datetime
- print ("Обработка файла = %s" % datetime.datetime.now())
- tree = etree.parse('-1.xml')
- offers = tree.xpath('/yml_catalog/shop/offers/offer')
- print ("Импорт в БД = %s" % datetime.datetime.now())
- connect = psycopg2.connect(database='DBNAME', user='DBUSER', host='DBHOST', password='DBPASS')
- cursor = connect.cursor()
- for offer in offers:
- name = offer.find('name').text
- #available = offer.get('available') #attr
- id = offer.get('id')
- #print id, name
- cursor.execute('INSERT INTO table (name, pid) VALUES (%s, %s)', (name, id))
- connect.commit()
- connect.close()
- print ("Завершение импорта = %s" % datetime.datetime.now())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement