old_contents: import simplejson
  import urllib
  import urllib2
  import apikey
  import logging
  import pickle_tool
  import time
  
  logging.basicConfig(level=logging.DEBUG)
  logger = logging.getLogger(__name__)
  
  
  def scan_url(resource):
      '''Sent a URLs sacn request to virustotal'''
      logger.debug('%s Checking virustotal' % resource)
      url = "https://www.virustotal.com/vtapi/v2/url/report"
      parameters = {"resource": resource, "apikey": apikey.APIKEY_0}
      data = urllib.urlencode(parameters)
      req = urllib2.Request(url, data)
      response = urllib2.urlopen(req)
      json = response.read()
      if json:
          response_dict = simplejson.loads(json)
          return response_dict.get('positives')
      else:
          return -1
  
  
  def update_local_cache():
      '''Self update the exist URLs in pickle'''
      cache = pickle_tool.check_pickle()
      for resource in cache.keys():
          positives = scan_url(resource)
          if positives >= 0:
              logger.debug('Now scan %s' % resource)
              cache[resource] = positives
              time.sleep(1)
          else:
              logger.info('%s Scan Faild wait 60 sec' % resource)
              time.sleep(60)
  
      pickle_tool.update_pickle(cache)
  
new_contents: import requests
  import apikey
  from pprint import pprint
  
  
  def domain_report(resource):
      parameters = {"domain": resource, "apikey": apikey.APIKEY_0}
      res = requests.get('https://www.virustotal.com/vtapi/v2/domain/report',
                         params=parameters)
      response_json = res.json()
      # pprint(response_json)
      if response_json:
          positives = response_json.get('detected_urls')[0].get('positives')
          return positives
      else:
          return -1
  
  
  def ip_report(resource):
      parameters = {"ip": resource, "apikey": apikey.APIKEY_0}
      res = requests.get(
          'https://www.virustotal.com/vtapi/v2/ip-address/report',
          params=parameters)
      response_json = res.json()
      # pprint(response_json)
      if response_json:
          positives = response_json.get('detected_urls')[0].get('positives')
          return positives
      else:
          return -1
  
  
  def url_report(resource):
      '''Sent a URLs sacn request to virustotal'''
      parameters = {"resource": resource, "apikey": apikey.APIKEY_0}
      res = requests.get('https://www.virustotal.com/vtapi/v2/url/report',
                         params=parameters)
      response_json = res.json()
      # pprint(response_json)
      if response_json:
          positives = response_json.get('positives')
          if positives is None:
              print "No report. Summit the URL."
              submit_url(resource)
          else:
              return positives
      else:
          return -1
  
  
  def submit_url(url):
      parameters = {"apikey": apikey.APIKEY_0, 'url': url}
      res = requests.post('https://www.virustotal.com/vtapi/v2/url/scan',
                          params=parameters)
      response_json = res.json()
      if response_json:
          response_code = response_json.get('response_code')
          # pprint(response_json)
          if response_code != 1:
              print "Fail submitted"
  
  
  if __name__ == '__main__':
      pass
  
subject: Add domain report/ip report/scan url functions