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')
        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 "Submitted Failed"
            with open('submitted_failed.log', 'a') as fp:
                fp.write('{u}\n'.format(u=url))


if __name__ == '__main__':
    pass

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, "scan": 1}
    res = requests.get('https://www.virustotal.com/vtapi/v2/url/report',
                       params=parameters)
    response_json = res.json()
    # pprint(response_json)
    if response_json:
        response_code = response_json.get('response_code')

        if response_code != 1:
            print "Submitted Failed"
            with open('submitted_failed.log', 'a') as fp:
                fp.write('{u}\n'.format(u=resource))
        else:
            positives = response_json.get('positives')
            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 "Submitted Failed"
            with open('submitted_failed.log', 'a') as fp:
                fp.write('{u}\n'.format(u=url))


if __name__ == '__main__':
    pass

add scan=1 optional params