populateTinyDB.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:NetSpark-Scripts 作者: admiralspark 项目源码 文件源码
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'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号