import json
import pandas
'''
For testing JSON interacion with Virustotal API.
Virustotal API response is JSON, and this is onwe of those replies.
This can be used for testing out various ways of displaying JSON strings
'''

data = '''{
    "meta": {
        "file_info": {
            "sha256": "72c742740de1958d148999600ab2eca7cda47286aafe3ef2c28c3bc395920285",
            "sha1": "b82428b6d9a36c3ce5ca3c601ac5df9d1c5565b7",
            "md5": "189c07138eba95f0a17d0332f4db8180",
            "size": 2496739
        }
    },
    "data": {
        "attributes": {
            "date": 1629173098,
            "status": "queued",
            "stats": {
                "harmless": 0,
                "type-unsupported": 0,
                "suspicious": 0,
                "confirmed-timeout": 0,
                "timeout": 0,
                "failure": 0,
                "malicious": 0,
                "undetected": 0
            },
            "results": {}
        },
        "type": "analysis",
        "id": "MTg5YzA3MTM4ZWJhOTVmMGExN2QwMzMyZjRkYjgxODA6MTYyOTE3MzA5OA==",
        "links": {
            "self": "https://www.virustotal.com/api/v3/analyses/MTg5YzA3MTM4ZWJhOTVmMGExN2QwMzMyZjRkYjgxODA6MTYyOTE3MzA5OA=="
        }
    }
}
'''

'''
json_data = json.loads(data)
print(json_data['data']['attributes']['status'])
'''

data = '''{
    "meta": {
        "file_info": {
            "sha256": "1c9cd40b037bbac4f4b236de657bab130200bb037c5df01372cc72b10144d7ab",
            "sha1": "7ba27f67d176574390d46c47a417e906893aeb40",
            "md5": "aca750302133b6541647a16f640a3769",
            "size": 1155778
        }
    },
    "data": {
        "attributes": {
            "date": 1629096305,
            "status": "completed",
            "stats": {
                "harmless": 0,
                "type-unsupported": 16,
                "suspicious": 0,
                "confirmed-timeout": 0,
                "timeout": 0,
                "failure": 0,
                "malicious": 0,
                "undetected": 58
            },
            "results": {
                "Bkav": {
                    "category": "undetected",
                    "engine_name": "Bkav",
                    "engine_version": "1.3.0.9899",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Lionic": {
                    "category": "undetected",
                    "engine_name": "Lionic",
                    "engine_version": "4.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Elastic": {
                    "category": "type-unsupported",
                    "engine_name": "Elastic",
                    "engine_version": "4.0.27",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210805"
                },
                "MicroWorld-eScan": {
                    "category": "undetected",
                    "engine_name": "MicroWorld-eScan",
                    "engine_version": "14.0.409.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "FireEye": {
                    "category": "undetected",
                    "engine_name": "FireEye",
                    "engine_version": "32.44.1.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "CAT-QuickHeal": {
                    "category": "undetected",
                    "engine_name": "CAT-QuickHeal",
                    "engine_version": "14.00",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "McAfee": {
                    "category": "undetected",
                    "engine_name": "McAfee",
                    "engine_version": "6.0.6.653",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Malwarebytes": {
                    "category": "undetected",
                    "engine_name": "Malwarebytes",
                    "engine_version": "4.2.2.27",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Zillya": {
                    "category": "undetected",
                    "engine_name": "Zillya",
                    "engine_version": "2.0.0.4429",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210813"
                },
                "Sangfor": {
                    "category": "undetected",
                    "engine_name": "Sangfor",
                    "engine_version": "2.9.0.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210625"
                },
                "K7AntiVirus": {
                    "category": "undetected",
                    "engine_name": "K7AntiVirus",
                    "engine_version": "11.204.37999",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Alibaba": {
                    "category": "type-unsupported",
                    "engine_name": "Alibaba",
                    "engine_version": "0.3.0.5",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20190527"
                },
                "K7GW": {
                    "category": "undetected",
                    "engine_name": "K7GW",
                    "engine_version": "11.204.37999",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Trustlook": {
                    "category": "type-unsupported",
                    "engine_name": "Trustlook",
                    "engine_version": "1.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Baidu": {
                    "category": "undetected",
                    "engine_name": "Baidu",
                    "engine_version": "1.0.0.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20190318"
                },
                "Cyren": {
                    "category": "undetected",
                    "engine_name": "Cyren",
                    "engine_version": "6.3.0.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "SymantecMobileInsight": {
                    "category": "type-unsupported",
                    "engine_name": "SymantecMobileInsight",
                    "engine_version": "2.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210126"
                },
                "Symantec": {
                    "category": "undetected",
                    "engine_name": "Symantec",
                    "engine_version": "1.15.0.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "ESET-NOD32": {
                    "category": "undetected",
                    "engine_name": "ESET-NOD32",
                    "engine_version": "23800",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "APEX": {
                    "category": "type-unsupported",
                    "engine_name": "APEX",
                    "engine_version": "6.197",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210813"
                },
                "TrendMicro-HouseCall": {
                    "category": "undetected",
                    "engine_name": "TrendMicro-HouseCall",
                    "engine_version": "10.0.0.1040",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Avast": {
                    "category": "undetected",
                    "engine_name": "Avast",
                    "engine_version": "21.1.5827.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "ClamAV": {
                    "category": "undetected",
                    "engine_name": "ClamAV",
                    "engine_version": "0.103.3.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Kaspersky": {
                    "category": "undetected",
                    "engine_name": "Kaspersky",
                    "engine_version": "21.0.1.45",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "BitDefender": {
                    "category": "undetected",
                    "engine_name": "BitDefender",
                    "engine_version": "7.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "NANO-Antivirus": {
                    "category": "undetected",
                    "engine_name": "NANO-Antivirus",
                    "engine_version": "1.0.146.25311",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "SUPERAntiSpyware": {
                    "category": "undetected",
                    "engine_name": "SUPERAntiSpyware",
                    "engine_version": "5.6.0.1032",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210814"
                },
                "Tencent": {
                    "category": "undetected",
                    "engine_name": "Tencent",
                    "engine_version": "1.0.0.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Ad-Aware": {
                    "category": "undetected",
                    "engine_name": "Ad-Aware",
                    "engine_version": "3.0.21.179",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "TACHYON": {
                    "category": "undetected",
                    "engine_name": "TACHYON",
                    "engine_version": "2021-08-16.02",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Sophos": {
                    "category": "undetected",
                    "engine_name": "Sophos",
                    "engine_version": "1.3.0.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Comodo": {
                    "category": "undetected",
                    "engine_name": "Comodo",
                    "engine_version": "33807",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "F-Secure": {
                    "category": "undetected",
                    "engine_name": "F-Secure",
                    "engine_version": "12.0.86.52",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "DrWeb": {
                    "category": "undetected",
                    "engine_name": "DrWeb",
                    "engine_version": "7.0.49.9080",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "VIPRE": {
                    "category": "undetected",
                    "engine_name": "VIPRE",
                    "engine_version": "94780",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "TrendMicro": {
                    "category": "undetected",
                    "engine_name": "TrendMicro",
                    "engine_version": "11.0.0.1006",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "McAfee-GW-Edition": {
                    "category": "undetected",
                    "engine_name": "McAfee-GW-Edition",
                    "engine_version": "v2019.1.2+3728",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "SentinelOne": {
                    "category": "type-unsupported",
                    "engine_name": "SentinelOne",
                    "engine_version": "6.1.0.4",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210805"
                },
                "Trapmine": {
                    "category": "type-unsupported",
                    "engine_name": "Trapmine",
                    "engine_version": "3.5.0.1023",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20200727"
                },
                "CMC": {
                    "category": "undetected",
                    "engine_name": "CMC",
                    "engine_version": "2.10.2019.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Emsisoft": {
                    "category": "undetected",
                    "engine_name": "Emsisoft",
                    "engine_version": "2021.4.0.5819",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Paloalto": {
                    "category": "type-unsupported",
                    "engine_name": "Paloalto",
                    "engine_version": "1.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "GData": {
                    "category": "undetected",
                    "engine_name": "GData",
                    "engine_version": "A:25.30590B:27.24108",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Jiangmin": {
                    "category": "undetected",
                    "engine_name": "Jiangmin",
                    "engine_version": "16.0.100",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Webroot": {
                    "category": "type-unsupported",
                    "engine_name": "Webroot",
                    "engine_version": "1.0.0.403",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Avira": {
                    "category": "undetected",
                    "engine_name": "Avira",
                    "engine_version": "8.3.3.12",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "eGambit": {
                    "category": "type-unsupported",
                    "engine_name": "eGambit",
                    "engine_version": null,
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Antiy-AVL": {
                    "category": "undetected",
                    "engine_name": "Antiy-AVL",
                    "engine_version": "3.0.0.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Kingsoft": {
                    "category": "undetected",
                    "engine_name": "Kingsoft",
                    "engine_version": "2017.9.26.565",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Gridinsoft": {
                    "category": "undetected",
                    "engine_name": "Gridinsoft",
                    "engine_version": "1.0.51.144",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Arcabit": {
                    "category": "undetected",
                    "engine_name": "Arcabit",
                    "engine_version": "1.0.0.886",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "ViRobot": {
                    "category": "undetected",
                    "engine_name": "ViRobot",
                    "engine_version": "2014.3.20.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "ZoneAlarm": {
                    "category": "undetected",
                    "engine_name": "ZoneAlarm",
                    "engine_version": "1.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Avast-Mobile": {
                    "category": "type-unsupported",
                    "engine_name": "Avast-Mobile",
                    "engine_version": "210815-00",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Microsoft": {
                    "category": "undetected",
                    "engine_name": "Microsoft",
                    "engine_version": "1.1.18400.5",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Cynet": {
                    "category": "undetected",
                    "engine_name": "Cynet",
                    "engine_version": "4.0.0.27",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "BitDefenderFalx": {
                    "category": "type-unsupported",
                    "engine_name": "BitDefenderFalx",
                    "engine_version": "2.0.936",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210610"
                },
                "AhnLab-V3": {
                    "category": "undetected",
                    "engine_name": "AhnLab-V3",
                    "engine_version": "3.20.4.10148",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Acronis": {
                    "category": "type-unsupported",
                    "engine_name": "Acronis",
                    "engine_version": "1.1.1.82",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210512"
                },
                "VBA32": {
                    "category": "undetected",
                    "engine_name": "VBA32",
                    "engine_version": "5.0.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210813"
                },
                "ALYac": {
                    "category": "undetected",
                    "engine_name": "ALYac",
                    "engine_version": "1.1.3.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "MAX": {
                    "category": "undetected",
                    "engine_name": "MAX",
                    "engine_version": "2019.9.16.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Cylance": {
                    "category": "type-unsupported",
                    "engine_name": "Cylance",
                    "engine_version": "2.3.1.101",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Zoner": {
                    "category": "undetected",
                    "engine_name": "Zoner",
                    "engine_version": "0.0.0.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Rising": {
                    "category": "undetected",
                    "engine_name": "Rising",
                    "engine_version": "25.0.0.26",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "Yandex": {
                    "category": "undetected",
                    "engine_name": "Yandex",
                    "engine_version": "5.5.2.24",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210814"
                },
                "Ikarus": {
                    "category": "undetected",
                    "engine_name": "Ikarus",
                    "engine_version": "0.1.5.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "MaxSecure": {
                    "category": "undetected",
                    "engine_name": "MaxSecure",
                    "engine_version": "1.0.0.1",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "Fortinet": {
                    "category": "undetected",
                    "engine_name": "Fortinet",
                    "engine_version": "6.2.142.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                },
                "BitDefenderTheta": {
                    "category": "undetected",
                    "engine_name": "BitDefenderTheta",
                    "engine_version": "7.2.37796.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210803"
                },
                "Cybereason": {
                    "category": "type-unsupported",
                    "engine_name": "Cybereason",
                    "engine_version": "1.2.449",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210330"
                },
                "Panda": {
                    "category": "undetected",
                    "engine_name": "Panda",
                    "engine_version": "4.6.4.2",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210815"
                },
                "CrowdStrike": {
                    "category": "type-unsupported",
                    "engine_name": "CrowdStrike",
                    "engine_version": "1.0",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210203"
                },
                "Qihoo-360": {
                    "category": "undetected",
                    "engine_name": "Qihoo-360",
                    "engine_version": "1.0.0.1300",
                    "result": null,
                    "method": "blacklist",
                    "engine_update": "20210816"
                }
            }
        },
        "type": "analysis",
        "id": "YWNhNzUwMzAyMTMzYjY1NDE2NDdhMTZmNjQwYTM3Njk6MTYyOTA5NjMwNQ==",
        "links": {
            "self": "https://www.virustotal.com/api/v3/analyses/YWNhNzUwMzAyMTMzYjY1NDE2NDdhMTZmNjQwYTM3Njk6MTYyOTA5NjMwNQ=="
        }
    }
}
'''

json_data = json.loads(data)
# print(json_data['data']['attributes']['results'])
av_engines = json_data['data']['attributes']['results'].keys()
av_engines_list = json_data['data']['attributes']['results']
# print(av_engines)

'''
undetected = 0
detected = 0
unsupported = 0
total = 0
for av_engine in av_engines:
    print(av_engines_list[av_engine]['category'])
    if av_engines_list[av_engine]['category'] == 'undetected':
        undetected = undetected + 1
        total = total + 1
    elif av_engines_list[av_engine]['category'] == 'detected':
        detected = detected + 1
        total = total + 1
    elif av_engines_list[av_engine]['category'] == 'type-unsupported':
        unsupported = unsupported +1
        total = total + 1
    else:
        total = total + 1

print('Detected : ' + str(detected) + '/' + str(total))
print('Undetected : ' + str(undetected) + '/' + str(total))
print('Type unsupported : ' + str(unsupported) + '/' + str(total))
'''

'''
print('DETECTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'detected':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\tDetected')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\tDetected')
        else:
            print(str(av_engine) + '\t\t\tDetected')
print('-----------------------------------------------')
print('UNDETECTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'undetected':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\tUndetected')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\tUndetected')
        else:
            print(str(av_engine) + '\t\t\tUndetected')
print('-----------------------------------------------')
print('TYPE UNSUPPORTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'type-unsupported':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\ttype-unsupported')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\ttype-unsupported')
        else:
            print(str(av_engine) + '\t\t\ttype-unsupported')
print('-----------------------------------------------')
'''

'''
print('DETECTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'detected':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\tDetected', end='')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\tDetected', end='')
        else:
            print(str(av_engine) + '\t\t\tDetected', end='')
        print('\tMethod : ' + str(av_engines_list[av_engine]['method']) +
              '\tResult : ' + str(av_engines_list[av_engine]['result']))
print('-----------------------------------------------')
print('UNDETECTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'undetected':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\tUndetected', end='')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\tUndetected', end='')
        else:
            print(str(av_engine) + '\t\t\tUndetected', end='')
        print('\tMethod : ' + str(av_engines_list[av_engine]['method']) +
              '\tResult : ' + str(av_engines_list[av_engine]['result']))
print('-----------------------------------------------')
print('TYPE UNSUPPORTED')
for av_engine in av_engines:
    if av_engines_list[av_engine]['category'] == 'type-unsupported':
        if len(av_engine) >= 16:
            print(str(av_engine) + '\ttype-unsupported', end='')
        elif len(av_engine) >= 8:
            print(str(av_engine) + '\t\ttype-unsupported', end='')
        else:
            print(str(av_engine) + '\t\t\ttype-unsupported', end='')
        print('\tMethod : ' + str(av_engines_list[av_engine]['method']) +
              '\tResult : ' + str(av_engines_list[av_engine]['result']))
print('-----------------------------------------------')

'''

'''
df1 = pandas.DataFrame(av_engines_list)
df1 = df1.transpose()
print(df1.to_string())
'''
