text: import click
  import json
  from os import path
  from flask import Flask, render_template
  from flask_socketio import SocketIO, emit, disconnect
  
  from cve_web_backend.database import Database, CVE, update_table_items
  from cve_web_backend.utilities import parse_record, disassemble_cve_object
  from cve_web_backend.logging import logger, setup_logging
  
  app = Flask(
      __name__,
      template_folder = "templates",
      static_url_path='/static',
      static_folder='static'
  )
  async_mode = None
  app.config['SECRET_KEY'] = 'secret!'
  socket_ = SocketIO(app, async_mode=async_mode)
  
  @app.route('/')
  @app.route('/index')
  @app.route('/unpatched')
  def launch_page():
      db = Database()
      db.start_session()
      result = db.search_by_status("Unpatched")
      record = disassemble_cve_object(result)
      db.close_session()
      return render_template("index.html", async_mode=socket_.async_mode, record = record, name = "Unpatched Vulnerabilities", change_status = "Mark as Patched")
  
  @app.route('/patched')
  def patched_page():
      db = Database()
      db.start_session()
      result = db.search_by_status("Patched")
      record = disassemble_cve_object(result)
      db.close_session()
      db.close_connection()
      return render_template("index.html", async_mode=socket_.async_mode, record = record, name = "Patched Vulnerabilities", change_status = "Mark as Unpatched")
  
  
  @socket_.on('update_record', namespace='/update')
  def handle_update_record_event(json_list, change_status):
      db = Database()
      db.start_session()
      for item in json_list:
          cve_record = item['cve']
          package = item['package']
          version = item['version']
          if change_status == "Mark as Patched":
              if db.update_to_patched(cve_record, package, version):
                  emit('update_record_response', 
                      {'result': 'success'}
                  )
              else:
                  emit('update_record_response', 
                      {'result': 'fail'}
                  )
          elif change_status == "Mark as Unpatched":
              if db.update_to_unpatched(cve_record, package, version):
                  emit('update_record_response', 
                      {'result': 'success'}
                  )
              else:
                  emit('update_record_response', 
                      {'result': 'fail'}
                  )
      db.close_session()
      db.close_connection()
  
  @socket_.on('delete_record', namespace='/delete')
  def handle_update_record_event(json_list):
      db = Database()
      db.start_session()
      for item in json_list:
          id = item['id']
          cve_record = item['cve']
          package = item['package']
          version = item['version']
          if db.delete_item(id, cve_record, package, version):
              emit('delete_record_response', 
                  {'result': 'success'}
              )
          else:
              emit('delete_record_response', 
                  {'result': 'fail'}
              )
      db.close_session()
      db.close_connection()
  
  @click.command()
  def start_server():
      setup_logging()
      app.run(debug=True)
  
  @click.command()
  @click.argument('filename', default='report.cve')
  def start(filename):
      setup_logging()
  
      database = Database()
      database.start_session()
  
      group_patch = []
      group_unpatch = []
  
      if database.is_empty():
          logger.info('CVE table is empty')
          if not path.exists(filename):
              logger.error('the file %s does not exist. Exit...', filename)
              exit(1)
          group_patch, group_unpatch = parse_record(filename)
          
          objectList = []
          for item in group_patch:
              cve = CVE(cve_record = item['CVE'], status = item['CVE STATUS'],
                  description = item['CVE SUMMARY'], package = item['PACKAGE NAME'],
                  version = item['PACKAGE VERSION'], scorev2 = item['CVSS v2 BASE SCORE'], 
                  scorev3 = item['CVSS v3 BASE SCORE'], vector = item['VECTOR'],
                  link = item['MORE INFORMATION']
              )
              objectList.append(cve)
          database.add_all_items(objectList)
  
          
          objectList = []
          for item in group_unpatch:
              cve = CVE(cve_record = item['CVE'], status = item['CVE STATUS'],
                  description = item['CVE SUMMARY'], package = item['PACKAGE NAME'],
                  version = item['PACKAGE VERSION'], scorev2 = item['CVSS v2 BASE SCORE'], 
                  scorev3 = item['CVSS v3 BASE SCORE'], vector = item['VECTOR'],
                  link = item['MORE INFORMATION']
              )
              objectList.append(cve)
          database.add_all_items(objectList)
  
          database.close_session()
          database.close_connection()
      app.run()
  
  @click.command()
  @click.argument('filename', default='')
  def update_database(filename):
      setup_logging()
  
      database = Database()
      database.start_session()
      if not filename:
          logger.error('the filename is not provided. Nothing to do. Exit...')
          exit(1)
      elif not path.exists(filename):
          logger.error('the file %s does not exist. Exit...', filename)
          exit(1)
      if database.is_empty():
          logger.error("The database is empty, run `start` first, Exit...")
          exit(1)
      group_patch, group_unpatch = parse_record(filename)
      update_table_items(database, group_patch)
      update_table_items(database, group_unpatch)
  
  
  
  if __name__ == '__main__':
      start_server()