# add modules folder to interpreter path
import sys
import os
modules_path = '../../modules/'
if os.path.exists(modules_path):
    sys.path.insert(1, modules_path)

import requests
import random
import json
import network_constants

ports = []
# transaction hub in
ports.extend(range(30001, 30003))
# data hub
ports.extend(range(30101, 30110))
# transaction hub out
ports.extend(range(30201, 30205))

print(f"Checking {len(ports)} ports")

network_constants.HOST_IP
home_url = 'http://' + str(network_constants.HOST_IP) + ':{port}/'
debug_url = home_url + 'api/debug'
print(debug_url)

for port in ports:
    try:
        response = requests.get(home_url.replace("{port}", str(port)))
        print(response.text)

        data = {'data': f"Echo {str(random.random())}"}    
        response = requests.post(debug_url.replace("{port}", str(port)), json=data)
        # print(response.text)
    except:
        print(f"Didnt work for port {port}")