#!/usr/bin/python3

import pymongo
import os
import json

PORT=27017
client = pymongo.MongoClient("localhost", PORT)
db = client.cuckoo_db
collection = db.malware_results

SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__))
MAIN_DIR = os.path.join(SCRIPTS_DIR, "..")

def add_js(js):
    return collection.insert_one(js)

def get_errors(js_data):
    errors = js_data["debug"].get("errors", None)
    if errors is None:
        print("There is no 'errors' key in debug.")
        return None
    return errors

def get_all_malwares_of_db():
    print("Print all malwares found in db:")
    number = 0
    for a in collection.find():
        print(a["malware_name"])
        number += 1
    print(f"{number} malware found in db")

if __name__=="__main__":
    get_all_malwares_of_db()


