(data)
Given a list of data, adds the items to (or creates) a CSV file.
Given a list of data, adds the items to (or creates) a CSV file.
Given a list of data adds the items to ( or creates ) a CSV file .
def parse_to_csv(data):
    """Given a list of data, adds the items to (or creates) a CSV file."""
    if not os.path.isfile(csv_name):
        csv_file = open(csv_name, 'w', newline='')
        csv_writer = csv.writer(csv_file)
        top_row = [
            'IP', 'Host', 'OS', 'Proto', 'Port',
            'Service', 'Product', 'Service FP',
            'NSE Script ID', 'NSE Script Output', 'Notes'
        ]
        csv_writer.writerow(top_row)
        print('\n[+] The file {} does not exist. New file created!\n'.format(
                csv_name))
    else:
        try:
            csv_file = open(csv_name, 'a', newline='')
        except PermissionError as e:
            print("\n[-] Permission denied to open the file {}. "
                  "Check if the file is open and try again.\n".format(csv_name))
            print("Print data to the terminal:\n")
            if args.debug:
                print(e)
            for item in data:
                print(' '.join(item))
            exit()
        csv_writer = csv.writer(csv_file)
        print('\n[+] {} exists. Appending to file!\n'.format(csv_name))
    for item in data:
        csv_writer.writerow(item)
    csv_file.close()
def parse_to_csv ( data ) : if not os . path . isfile ( csv_name ) : csv_file = open ( csv_name , 'w' , newline = '' ) csv_writer = csv . writer ( csv_file ) top_row = [ 'IP' , 'Host' , 'OS' , 'Proto' , 'Port' , 'Service' , 'Product' , 'Service FP' , 'NSE Script ID' , 'NSE Script Output' , 'Notes' ] csv_writer . writerow ( top_row ) print ( '\n[+] The file {} does not exist. New file created!\n' . format ( csv_name ) ) else : try : csv_file = open ( csv_name , 'a' , newline = '' ) except PermissionError as e : print ( "\n[-] Permission denied to open the file {}. " "Check if the file is open and try again.\n" . format ( csv_name ) ) print ( "Print data to the terminal:\n" ) if args . debug : print ( e ) for item in data : print ( ' ' . join ( item ) ) exit ( ) csv_writer = csv . writer ( csv_file ) print ( '\n[+] {} exists. Appending to file!\n' . format ( csv_name ) ) for item in data : csv_writer . writerow ( item ) csv_file . close ( )