#!/usr/bin/env python2

import argparse
import json
import time
import virustotal
import os

v = virustotal.VirusTotal('8488f4b84e9c2010c95b17df236466a42f46e6762a2739da4caa6cf1c9178ad3')

parser = argparse.ArgumentParser(
  description='Scan a directory with VirusTotal.')
parser.add_argument('directory', type=str)
args = parser.parse_args()

if not os.path.isfile("db.json"):
  db = {}
else:
  f = open("db.json")
  db = json.load(f)
  f.close()

for fname in os.listdir(args.directory):
  if fname not in db:
    print(" + Scanning: '" + args.directory+"/"+fname + "'.")
    report = None
    while report is None:
      try:
        report = v.scan(args.directory+"/"+fname)
      except virustotal.VirusTotal.ApiError:
        print("   + Limit reached. Waiting.")
        time.sleep(15) # Seconds.
        pass

    report.join()

    malware_names = []
    for antivirus, malware in report:
      if malware is not None:
        malware_names.append(malware)

    db[fname] = {
      "total": report.total,
      "malware-positives": report.positives,
      "malware-names": malware_names
    }

    f = open("db.json", 'w')
    json.dump(db, f, indent=2)
    f.close()

#!/usr/bin/env python2

import argparse
import json
import time
import virustotal
import os

v = virustotal.VirusTotal('8488f4b84e9c2010c95b17df236466a42f46e6762a2739da4caa6cf1c9178ad3')

parser = argparse.ArgumentParser(
  description='Scan a directory with VirusTotal.')
parser.add_argument('directory', type=str)
parser.add_argument('output_json', type=str)
args = parser.parse_args()

if not os.path.isfile(args.output_json):
  db = {}
else:
  f = open(args.output_json)
  db = json.load(f)
  f.close()

for fname in os.listdir(args.directory):
  if os.path.getsize(args.directory+"/"+fname) > 32000000:
    continue
  if fname not in db:
    print(" + Scanning: '" + args.directory+"/"+fname + "'.")
    report = None; attempts = 0;
    while report is None and attempts < 5:
      try:
        report = v.scan(args.directory+"/"+fname)
        report.join()
      except:
        print("   + Limit reached (or other error). Waiting 15s.")
        time.sleep(15) # Seconds.
        attempts = attempts + 1
        pass

    if report:
      classifications = {}
      for antivirus, malware in report:
        classifications[antivirus[0]] = [antivirus[1], antivirus[2], malware]

      db[fname] = {
        "total": report.total,
        "malware-positives": report.positives,
        "uid": report.id,
        "scan uid": report.scan_id,
        "md5": report.md5,
        "status": report.status,
        "classifications": classifications
      }

      f = open(args.output_json, 'w')
      json.dump(db, f, indent=2)
      f.close()

Update virustotal script.