def populate():
''' Populates the DB with data. This is old code, needs cleanup '''
with open(filename, mode='r') as f:
reader = csv.DictReader(f)
# Now iterate through every row in the CSVfile and set variables
for row in reader:
ip = row['IP_Address']
hostname = row['SysName']
device_type = row['device_type']
department = row['Department']
switch = {
'ip': row['IP_Address'],
'hostname': row['SysName'],
'device_type': row['device_type'],
'department': row['Department']
}
dbf = Query()
resultf = db.search(dbf.ip == row['IP_Address'])
if str(resultf) != "[]":
print("Skipping " + row['IP_Address'] + " as it already exists.")
else:
db.insert(switch)
print ("Added " + row['IP_Address'])
评论列表
文章目录