From 0b88b0ab345a81e573f78402d393d418d3d38cca Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 27 Apr 2024 06:24:56 +0100 Subject: [PATCH] add region count and format the numbers --- .../piaservers/readme/ReadMeManager.java | 14 +++++++++----- src/main/resources/README.md | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java b/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java index 02d066e..326ff86 100644 --- a/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java +++ b/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java @@ -10,12 +10,14 @@ import java.io.File; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.text.DecimalFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; public class ReadMeManager { + private final DecimalFormat decimalFormat = new DecimalFormat("#,###.00"); @SneakyThrows public ReadMeManager() { @@ -31,16 +33,18 @@ public class ReadMeManager { // Get the contents of the README.md String contents = new String(readmeStream.readAllBytes()); - // Replace the placeholders in the README.md file - contents = contents.replace("{server_count}", String.valueOf(PiaManager.SERVERS.size())); - contents = contents.replace("{last_update}", new Date().toString().replaceAll(" ", "_")); - - // Write total servers per-region Map regionCounts = new HashMap<>(); for (PiaServer server : PiaManager.SERVERS) { String region = server.getRegion(); regionCounts.put(region, regionCounts.getOrDefault(region, 0) + 1); } + + // Replace the placeholders in the README.md file + contents = contents.replace("{server_count}", decimalFormat.format(PiaManager.SERVERS.size())); + contents = contents.replace("{last_update}", new Date().toString().replaceAll(" ", "_")); + contents = contents.replace("{region_count}", decimalFormat.format(regionCounts.size())); + + // Write total servers per-region contents = contents.replace("{server_table}", regionCounts.entrySet().stream() .sorted((a, b) -> Integer.compare(b.getValue(), a.getValue())) // Sort from highest to lowest .map(entry -> "| " + entry.getKey() + " | " + entry.getValue() + " |") // Map the region to the count diff --git a/src/main/resources/README.md b/src/main/resources/README.md index b3e51d8..00c59a2 100644 --- a/src/main/resources/README.md +++ b/src/main/resources/README.md @@ -1,6 +1,6 @@ # PIA Server List -![Servers](https://img.shields.io/badge/servers-{server_count}-blue) ![Last update](https://img.shields.io/badge/last_updated-{last_update}-blue) +![Servers](https://img.shields.io/badge/servers-{server_count}-blue) ![Regions](https://img.shields.io/badge/regions-{region_count}-blue) ![Last update](https://img.shields.io/badge/last_updated-{last_update}-blue) This is a list of the OpenVPN servers provided by Private Internet Access (PIA). The list is updated hourly.