Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import os
- import psycopg2
- path = 'custom_asn.csv'
- try:
- connection = psycopg2.connect(user = "scrutremote",
- password = "admin",
- host = "127.0.0.1",
- port = "5432",
- database = "plixer")
- cursor = connection.cursor()
- #delete old table.
- cursor.execute("""DELETE from plixer.asn_custom;""")
- connection.commit()
- cursor.close()
- connection.close()
- except (Exception, psycopg2.Error) as error :
- print ("Error while connecting to PostgreSQL", error)
- with open(path, 'r', encoding='utf-8', errors='ignore') as infile, open('/home/plixer/scrutinizer/files/custom_asn.import', 'w') as outfile:
- inputs = csv.reader(infile)
- output = csv.writer(outfile)
- #convert kinner csv - > one ready for import.
- for row in inputs:
- as_number = row[1]
- as_name = row[1] + ' ' + row[2]
- as_description = 'Covance ASN'
- as_subnet = row[3] + '/' + row[4]
- output.writerow([as_number,as_name,as_description,as_subnet])
- #run import
- os.system("scrut_util.exe /home/plixer/scrutinizer/bin/scrut_util.exe --import asns")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement