new_contents: import sqlite3
  
  
  class SQLiteTool(object):
      def __init__(self):
          self.conn = sqlite3.connect('url_reports.db')
  
      def creat(self):
          try:
              self.conn.execute('''CREATE TABLE URLREPORTS
                     (ID TEXT PRIMARY KEY     NOT NULL,
                     URL            TEXT     NOT NULL,
                     POSITIVE       INT);''')
              # print "Table created successfully"
          except sqlite3.OperationalError, e:
              pass
              # print e
  
      def __update(self, key, pos):
          self.conn.execute("UPDATE URLREPORTS set POSITIVE = %d where ID = '%s'"
                             % (pos, key))
          # print "Update Operation done successfully";
          self.conn.commit()
          # print "Total number of rows updated :", self.conn.total_changes
  
      def __insert(self, key, url, pos):
          try:
              self.conn.execute('''INSERT INTO URLREPORTS (ID,URL,POSITIVE)
                                   VALUES (?,?,?)''', (key, url, pos))
              self.conn.commit()
          except sqlite3.IntegrityError, e:
              print '[ERROR]', e
  
      def insert2(self, key, url, pos):
          key_in_table = None
          cursor = self.conn.execute("SELECT ID from URLREPORTS WHERE ID = '%s'"
                                      % key)
          for row in cursor:
              key_in_table = row[0]
  
          if key_in_table and  key_in_table == key:
              print "[INFO] Update it"
              # if the URL in the table update it
              self.__update(key, pos)
          else:
              print "[INFO] insert the table"
              # else insert the table
              self.__insert(key, url, pos)
  
      def show(self):
          cursor = self.conn.execute("SELECT ID, URL, POSITIVE from URLREPORTS")
          for row in cursor:
             print "ID = ", row[0]
             print "URL = ", row[1]
             print "POSITIVE = ", row[2]
  
      def __del__(self):
          self.conn.close()
  
  if __name__ == '__main__':
      import hashlib
      url = 'www.yahoo.com'
      key = hashlib.sha1(url).hexdigest()
      print "The key is: ", key
  
      sql = SQLiteTool()
      sql.creat()
  
      sql.insert2(key, url, 100)
  
      print "=== NOW TABLE ==="
      sql.show()
  
subject: Add SQL tool