__author__ = 'Nick@fina2.net'
import itertools
import urllib
import json
import urllib.request

print("Start");

host = "http://localhost:8080/rest/v1/"

request = urllib.request.Request(host + "partitionRandom")
response = urllib.request.urlopen(request)
data = json.loads(response.read().decode())

source = data['source']

print("source: " + source)

request = urllib.request.Request(host + "savePartition?word=" + source + "&status=1")
urllib.request.urlopen(request)

for x in itertools.permutations(source):
    request = urllib.request.Request(host + "saveKey?source=" + ''.join(x))
    urllib.request.urlopen(request)

request = urllib.request.Request(host + "savePartition?word=" + source + "&status=2")
urllib.request.urlopen(request)