import csv from models import Entrypoint from config import * ENTRYPOINTS = [] FILE_PATH = './config/result.csv' def read_csv(file_path): with open(file_path, 'r') as f: reader = csv.reader(f) for row in reader: yield row def reload_entrypoints(): global ENTRYPOINTS ENTRYPOINTS = [] for row in read_csv(FILE_PATH): if row[0].lower() == 'ip:port': continue ip, port = row[0].split(':') loss = float(row[1].replace('%', '')) delay = int(row[2].replace('ms', '')) if loss > LOSS_THRESHOLD or delay > DELAY_THRESHOLD: continue entrypoint = Entrypoint() entrypoint.ip = ip entrypoint.port = port entrypoint.loss = loss entrypoint.delay = delay ENTRYPOINTS.append(entrypoint) return ENTRYPOINTS def get_entrypoints(): if not ENTRYPOINTS: reload_entrypoints() return ENTRYPOINTS if __name__ == '__main__': reload_entrypoints() print(ENTRYPOINTS) print(len(ENTRYPOINTS))