Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import psycopg2
- from apilib.utils.seo import get_product_seo_url_tail
- if __name__ == '__main__':
- conn_string = "host='ddubinin.jail.local' port='1433' dbname='site' user='qa' password=''"
- conn = psycopg2.connect(conn_string)
- cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- while True:
- cursor.execute("""
- SELECT p.sku, p.type, p.name, b.url, b.name as brand_name
- FROM product p LEFT JOIN
- brand b ON (b.id = p.brand_id)
- WHERE p.seo_tail IS NULL
- LIMIT 100;
- """)
- if not cursor:
- break;
- update_cursor = conn.cursor()
- for row in cursor:
- seo_tail = get_product_seo_url_tail(row.get('type').decode('utf-8'), row.get('name').decode('utf-8'), row.get('url').decode('utf-8'))
- update_cursor.execute("""
- UPDATE product
- SET seo_tail = %(seo_tail)s,
- brand_name = %(brand_name)s
- WHERE sku = %(sku)s
- """, {
- 'seo_tail': seo_tail,
- 'brand_name': row.get('brand_name').decode('utf-8'),
- 'sku': row.get('sku')
- })
- conn.commit()
- update_cursor.close()
- cursor.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement