#!/usr/bin/env python

# Displays adjacent IP addresses, with a limit of 15.

# Runs GetElements to perform a query, and then uses Limit to restrict the
# data set to 15.

import requests
import json
import sys
from gaffer import Gaffer

gr = sys.stdin.read()
gr = json.loads(gr)


# Function allows management in chunks
def chunks(l, n):
    l = list(l)
    n = max(1, n)
    return (l[i:i+n] for i in xrange(0, len(l), n))

g = Gaffer("https://analytics.trustnetworks.com/gaffer-threat")
g.use_cert()
url = "/rest/v2/graph/operations/execute"
        
for i in chunks(gr, 500):

    query={
        "class": "uk.gov.gchq.gaffer.operation.impl.add.AddElements",
        "validate": True,
        "skipInvalidElements": False,
        "input": i
    }

    
    res = g.post(url, data=json.dumps(query))
    print res.status_code

    
    print res.text

