import requests
import pandas as pd
import pickle
from time import sleep

# This part of the code is to be manually edited:
#
# url='http://IP_OF_THE_PQoS:PORT_5000_INTERNALLY/accept_data'
url = 'http://192.168.2.213:5000/accept_data'             # url to send the request to
total_sets = 10                                           # The total number of sets of 100s to send to the PQoS
#
# End of the part to manually edit

def send_dataset(start, end, sets):
    try:
        dataset = pd.read_csv("test.csv")
        elements = dataset[start-1:end]
        to_send = pickle.dumps(elements)
        requests.post(url, data= to_send)
        sets += 1
        print("Dataset sent to PQoS")
        if (end < len(dataset)) and (sets != total_sets):
            sleep(5)
            send_dataset(start + 100, end + 100, sets)
    except requests.exceptions.RequestException as e:
        print(f"Error while sending data to PQoS: {e}")

sets = 0
send_dataset(1, 100, sets)
