fix
All checks were successful
Fetch new Pia Servers / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 3m17s

This commit is contained in:
Lee 2024-04-29 01:01:44 +01:00
parent 74c2c89385
commit e0ddf6c4bf
2 changed files with 6 additions and 8 deletions

@ -6,6 +6,8 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.SneakyThrows;
import java.util.concurrent.TimeUnit;
public class Main {
public static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
@ -13,7 +15,9 @@ public class Main {
@SneakyThrows
public static void main(String[] args) {
new PiaManager();
PiaManager.updateServers();
Thread.sleep(TimeUnit.MINUTES.toMillis(3));
PiaManager.updateServers();
new ReadMeManager();
}
}

@ -21,14 +21,13 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
public class PiaManager {
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
private static final String PIA_OPENVPN_CONFIGS_URL = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
private static final long REMOVAL_THRESHOLD = TimeUnit.DAYS.toMicros(14); // 2 weeks
public static List<PiaServer> SERVERS = new ArrayList<>();
@SneakyThrows
public PiaManager() {
public static void updateServers() {
File serversFile = new File("servers.json");
if (!serversFile.exists()) {
System.out.println("serversFile.json does not exist, creating...");
@ -55,11 +54,6 @@ public class PiaManager {
SERVERS.removeAll(toRemove); // Remove the servers
System.out.printf("Removed %s old servers\n", toRemove.size());
// Update the last seen time for all the servers
for (PiaServer server : SERVERS) {
server.setLastSeen(new Date());
}
// Add the new servers to the list
for (PiaServerToken serverToken : piaDomain) {
InetAddress address = InetAddress.getByName(serverToken.getHostname());