json_database icon indicating copy to clipboard operation
json_database copied to clipboard

why after serveral iteration it clear all database content without warning

Open wanghaisheng opened this issue 4 years ago • 2 comments

    db_path = "data/aww_reddit.db"
    print('add image process task',f)
    filename = os.path.basename(f).split('.')[0]
    videoid = b64e(filename)
    nowtime = time.time()
    update_time = int(nowtime)    
    data = {"videoid": videoid,
            "status": 0,
            "update_time": update_time}
    # data = json.dumps(data)
    with JsonDatabase("aww_reddit", db_path) as db:
        db.add_item(data)

update after creation

        data = {"videoid": videoid,
                "status": 1,
                "title": formattitle,
                "update_time": update_time,
                "des": des,
                'videopath': upload_video,
                'rapidtags': rapidtags,
                "tags": tags}

        with JsonDatabase("aww_reddit", db_path) as db:
            results = db.search_by_value("videoid", videoid)

            olditem =results[0]
            print(olditem)
            item_id = db.get_item_id(olditem)

            if item_id >= 0:
                db.update_item(item_id, data)

            else:
                print("item not found in database")

@kevinelgan

  File "D:\Program Files\anaconda3\lib\site-packages\json_database\__init__.py", line 189, in add_item
    if allow_duplicates or value not in self:   
  File "D:\Program Files\anaconda3\lib\site-packages\json_database\__init__.py", line 163, in __contains__
    return item in self.db[self.name]
KeyError: 'aww_reddit'

wanghaisheng avatar Sep 09 '21 00:09 wanghaisheng