old_contents: import requests
  import os.path
  
  class VirusTotal():
  
      def __init__(self, apikey):
          self.apikey = apikey
  
      def scan(self, path):
          with open(path, 'rb') as f:
              params = {'apikey': self.apikey}
              files = {'file': (os.path.basename(path), f)}
              url = 'https://www.virustotal.com/vtapi/v2/file/scan'
              res = requests.post(url, files=files, params=params)
          return res.json()['resource']
  
      def get_report(self, resource):
          params = {'apikey': apikey, 'resource': resource}
          url = 'https://www.virustotal.com/vtapi/v2/file/report'
          return requests.get(url, params=params).json()
  
      def get_num_detected(self, resource):
          report = self.get_report(resource)
          return sum(scan['detected'] for av, scan in report['scans'].items())
  
  
new_contents: from threading import Semaphore
  from os.path import basename
  from rate import ratelimiter
  import requests
  
  
  class VirusTotal():
  
      def __init__(self, apikey, limit=4, every=60):
          self.semaphore = threading.Semaphore(limit)
          self.apikey = apikey
          self.every = every
  
      def scan(self, path):
          with ratelimiter(self.semaphore, self.every):
              with open(path, 'rb') as f:
                  params = {'apikey': self.apikey}
                  files = {'file': (basename(path), f)}
                  url = 'https://www.virustotal.com/vtapi/v2/file/scan'
                  res = requests.post(url, files=files, params=params)
              return res.json()['resource']
  
      def get_report(self, resource):
          with ratelimiter(self.semaphore, self.every):
              params = {'apikey': apikey, 'resource': resource}
              url = 'https://www.virustotal.com/vtapi/v2/file/report'
              return requests.get(url, params=params).json()
  
      def get_num_detected(self, resource):
          report = self.get_report(resource)
          return sum(scan['detected'] for av, scan in report['scans'].items())
  
  
subject: Use ratelimiter in vt.py