add readme
Some checks failed
Fetch new Pia Servers / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 15s

This commit is contained in:
Lee 2024-04-27 05:49:10 +01:00
parent e8fb29a911
commit 92c6bcf3be
6 changed files with 3933 additions and 9 deletions

@ -46,6 +46,7 @@ jobs:
git config --global user.email "liam@fascinated.cc"
git config --global user.name "Liam"
git add servers.json
git commit -m "Update PIA Servers"
git add readme.me
git commit -m "Scheduled update"
git push https://fascinated:${{ secrets.AUTH_TOKEN }}@git.fascinated.cc/Fascinated/PIA-Servers

File diff suppressed because it is too large Load Diff

@ -1,6 +1,7 @@
package cc.fascinated.piaservers;
import cc.fascinated.piaservers.pia.PiaManager;
import cc.fascinated.piaservers.readme.ReadMeManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.SneakyThrows;
@ -13,5 +14,6 @@ public class Main {
@SneakyThrows
public static void main(String[] args) {
new PiaManager();
new ReadMeManager();
}
}

@ -25,6 +25,7 @@ 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() {
@ -38,20 +39,20 @@ public class PiaManager {
System.out.println("Found " + piaDomain.size() + " pia domains");
// Load the serversFile from the file
List<PiaServer> servers = Main.GSON.fromJson(Files.readString(serversFile.toPath()), new TypeToken<List<PiaServer>>() {}.getType());
if (servers == null) {
servers = new ArrayList<>();
SERVERS = Main.GSON.fromJson(Files.readString(serversFile.toPath()), new TypeToken<List<PiaServer>>() {}.getType());
if (SERVERS == null) {
SERVERS = new ArrayList<>();
}
List<PiaServer> toRemove = new ArrayList<>();
System.out.println("Removing old servers...");
// Get the servers that need to be removed
for (PiaServer server : servers) {
for (PiaServer server : SERVERS) {
if (server.getLastSeen().getTime() < System.currentTimeMillis() - REMOVAL_THRESHOLD) {
toRemove.add(server);
}
}
servers.removeAll(toRemove); // Remove the servers
SERVERS.removeAll(toRemove); // Remove the servers
System.out.printf("Removed %s old servers\n", toRemove.size());
// Add the new servers to the list
@ -59,12 +60,12 @@ public class PiaManager {
InetAddress address = InetAddress.getByName(serverToken.getHostname());
// Add the server to the list
servers.add(new PiaServer(address.getHostAddress(), serverToken.getRegion(), new Date()));
SERVERS.add(new PiaServer(address.getHostAddress(), serverToken.getRegion(), new Date()));
}
// Save the servers to the file
Files.writeString(serversFile.toPath(), Main.GSON.toJson(servers));
System.out.printf("Wrote %s servers to the file\n", servers.size());
Files.writeString(serversFile.toPath(), Main.GSON.toJson(SERVERS));
System.out.printf("Wrote %s servers to the file\n", SERVERS.size());
}
@SneakyThrows

@ -0,0 +1,35 @@
package cc.fascinated.piaservers.readme;
import cc.fascinated.piaservers.Main;
import cc.fascinated.piaservers.pia.PiaManager;
import lombok.SneakyThrows;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Date;
import java.util.List;
public class ReadMeManager {
@SneakyThrows
public ReadMeManager() {
InputStream readmeStream = Main.class.getResourceAsStream("/README.md");
if (readmeStream == null) {
System.out.println("Failed to find README.md");
return;
}
File readmeFile = new File("README.md");
if (!readmeFile.exists()) {
readmeFile.createNewFile();
}
String contents = new String(readmeStream.readAllBytes());
contents = contents.replace("{server_count}", String.valueOf(PiaManager.SERVERS.size()));
contents = contents.replace("{last_update}", new Date().toString().replaceAll(" ", "_"));
Files.write(readmeFile.toPath(), contents.getBytes());
}
}

@ -0,0 +1,5 @@
# PIA Server List
![Servers](https://img.shields.io/badge/servers-{server_count}-brightgreen) ![Last update](https://img.shields.io/badge/{last_update}-brightgreen)
This is a list of the OpenVPN servers provided by Private Internet Access (PIA). The list is updated hourly.