def flush_data(address, username, data):
    if data:
        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
    return []

def fetch_output(address, username):
    val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username})), timeout=10).read()
    l, r = output.split("&", 1)
    if "value" in l:
        output = r
    else:
        output = l
    _, output = output.split("=", 1)
    return output

def send_to_mv(address, username, lst):
    data = []
    variables = {}

    for c in lst:
        if isinstance(c, int):
            data = flush_data(address, username, data)
            variables[c] = fetch_output(address, username)
        else:
            data.append(c)

    return variables
