# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import sqlite3

class Demo2Pipeline(object):
    def __init__(self):
        self.create_connection()
        self.create_table()
    def create_connection(self):
        self.conn = sqlite3.connect("myntra.db")
        self.curr = self.conn.cursor()
        
    def create_table(self):
            self.curr.execute("""DROP TABLE IF EXISTS questions""")
            self.curr.execute(""" create table caps (
               brand_name text,
               price text,
               discount text )
               """)
                              
    def process_item(self, item, spider):
        self.store_db(item)
        return item
    
    def store_db(self,item):
        self.curr.execute("""insert into caps values (?,?,?)""",
                          (item['brand_name'],
                           item['price'],
                           item['discount']
                            ))
        self.conn.commit()
