From 307a471dd9008b18ea1f786626b21ca61c859fff Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 29 Apr 2024 01:27:21 -0400 Subject: [PATCH] changes --- .gitea/workflows/sync-servers.yml | 2 +- .../java/me/braydon/pia/PIAServerList.java | 44 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.gitea/workflows/sync-servers.yml b/.gitea/workflows/sync-servers.yml index cc634e5ab..2bd93715b 100644 --- a/.gitea/workflows/sync-servers.yml +++ b/.gitea/workflows/sync-servers.yml @@ -2,7 +2,7 @@ name: Sync PIA Servers on: schedule: - - cron: "*/15 * * * *" + - cron: "*/20 * * * *" push: branches: ["master"] paths: [".gitea/workflows/sync-servers.yml", "src/**", "pom.xml"] diff --git a/src/main/java/me/braydon/pia/PIAServerList.java b/src/main/java/me/braydon/pia/PIAServerList.java index 3f56e41d9..840d8cf7e 100644 --- a/src/main/java/me/braydon/pia/PIAServerList.java +++ b/src/main/java/me/braydon/pia/PIAServerList.java @@ -32,38 +32,34 @@ public final class PIAServerList { @SneakyThrows public static void main(@NonNull String[] args) { Map regionAddresses = getRegionAddresses(); // Get region address from PIA - Set servers = new HashSet<>(); for (int i = 0; i < TOTAL_RUNS; i++) { + Set servers = getNewServers(regionAddresses); // Get the new servers from PIA int before = servers.size(); - servers.addAll(getNewServers(regionAddresses)); // Add new servers from PIA - System.out.println("Added " + (servers.size() - before) + " new server(s) from PIA"); + servers.addAll(loadServersFromFile()); // Load servers from the file + System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file"); - // Sleep for 3 mins + // Delete servers that haven't been seen in more than a week + before = servers.size(); + servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L)); + System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week"); + + // Write the servers to the servers file + System.out.println("Writing servers file..."); + try (FileWriter fileWriter = new FileWriter(SERVERS_FILE)) { + GSON.toJson(servers, fileWriter); + } + System.out.println("Done, wrote " + servers.size() + " servers to the file"); + + // Update the README.md file + ReadMeManager.update(servers); + + // Sleep before running again if (i < TOTAL_RUNS - 1) { - System.out.println("Sleeping, waiting for another run..."); + System.out.println("Sleeping..."); Thread.sleep(TimeUnit.MINUTES.toMillis(4L)); } } - - // Delete servers that haven't been seen in more than a week - int before = servers.size(); - servers.addAll(loadServersFromFile()); // Load servers from the file - System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file"); - - before = servers.size(); - servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L)); - System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week"); - - // Write the servers to the servers file - System.out.println("Writing servers file..."); - try (FileWriter fileWriter = new FileWriter(SERVERS_FILE)) { - GSON.toJson(servers, fileWriter); - } - System.out.println("Done, wrote " + servers.size() + " servers to the file"); - - // Update the README.md file - ReadMeManager.update(servers); } /**