Fix CSV parsing dates with commas. Fix UEE record scraping

This commit is contained in:
Dork Normalize 2025-03-30 19:01:50 -07:00
parent d817b097ab
commit 3f892c6a37
3 changed files with 42 additions and 26 deletions

View file

@ -146,11 +146,27 @@ public partial class HomePage : UserControl
EnemyPilot = actorDeathData.VictimPilot,
EnemyShip = actorDeathData.VictimShip,
OrgAffiliation = playerData?.OrgName,
Weapon = actorDeathData.Weapon,
Ship = LocalPlayerData.PlayerShip ?? "Unknown",
Method = actorDeathData.DamageType,
RecordNumber = playerData?.UEERecord,
GameVersion = LocalPlayerData.GameVersion ?? "Unknown",
TrackRver = UpdatePage.currentVersion.Replace("v", "") ?? "Unknown",
Enlisted = playerData?.JoinDate,
KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"),
PFP = playerData?.PFPURL
PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"
};
switch (LocalPlayerData.CurrentGameMode)
{
case GameMode.PersistentUniverse:
killData.Mode = "pu";
break;
case GameMode.ArenaCommander:
killData.Mode = "ac";
break;
}
// Add kill to UI
Dispatcher.Invoke(() =>
{
@ -160,7 +176,7 @@ public partial class HomePage : UserControl
// Only submit kill data if not in offline mode
if (ConfigManager.OfflineMode == 0)
{
await WebHandler.SubmitKill(actorDeathData, playerData);
await WebHandler.SubmitKill(killData);
}
_killHistoryManager.AddKill(killData);
@ -234,6 +250,8 @@ public partial class HomePage : UserControl
FontFamily = orbitronFontFamily,
});
killTextBlock.Inlines.Add(new Run($"{killData.RecordNumber}\n"));
killTextBlock.Inlines.Add(new Run("Kill Time: ")
{
Foreground = altTextColorBrush,
@ -261,6 +279,11 @@ public partial class HomePage : UserControl
// Add the TextBlock to the first column of the Grid
Grid.SetColumn(killTextBlock, 0);
killGrid.Children.Add(killTextBlock);
if (killData.PFP == "")
{
killData.PFP = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg";
}
// Create the Image for the profile
var profileImage = new Image

View file

@ -28,6 +28,9 @@ public class KillHistoryManager
File.WriteAllText(_killHistoryPath, _headers);
}
// Remove comma from Enlisted
killData.Enlisted = killData.Enlisted?.Replace(",", string.Empty);
// Append the new kill data to the CSV file
var csv = new StringBuilder();
csv.AppendLine($"\"{killData.KillTime}\",\"{killData.EnemyPilot}\",\"{killData.EnemyShip}\",\"{killData.Enlisted}\",\"{killData.RecordNumber}\",\"{killData.OrgAffiliation}\",\"{killData.Player}\",\"{killData.Weapon}\",\"{killData.Ship}\",\"{killData.Method}\",\"{killData.Mode}\",\"{killData.GameVersion}\",\"{killData.TrackRver}\",\"{killData.Logged}\",\"{killData.PFP}\"");

View file

@ -27,7 +27,7 @@ public static class WebHandler
public static async Task<PlayerData?> GetPlayerData(string enemyPilot)
{
var joinDataPattern = new Regex("<span class=\"label\">Enlisted</span>\\s*<strong class=\"value\">([^<]+)</strong>");
var ueePattern = new Regex("<p class=\"entry citizen-record\">\\s*<span class=\"label\">UEE Citizen Record<\\/span>\\s*<strong class=\"value\">#?(n\\/a|\\d+)<\\/strong>\\s*<\\/p>");
var ueePattern = new Regex("<p class=\"entry citizen-record\">\\n.*.<span class=\"label\">UEE Citizen Record<\\/span>\\n.*.<strong class=\"value\">#(?<UEERecord>\\d+)<\\/strong>");
var orgPattern = new Regex("\\/orgs\\/(?<OrgURL>[A-z0-9]+)\" .*\\>(?<OrgName>.*)<");
var pfpPattern = new Regex("/media/(.*)\"");
@ -51,7 +51,7 @@ public static class WebHandler
var ueeMatch = ueePattern.Match(content);
if (ueeMatch.Success)
{
playerData.UEERecord = ueeMatch.Groups[1].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value;
playerData.UEERecord = ueeMatch.Groups["UEERecord"].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value;
}
var orgMatch = orgPattern.Match(content);
@ -78,33 +78,23 @@ public static class WebHandler
return playerData;
}
public static async Task SubmitKill(ActorDeathData deathData, PlayerData? enemyPlayerData)
public static async Task SubmitKill(KillData killData)
{
var killData = new APIKillData
var apiKillData = new APIKillData
{
victim_ship = deathData.VictimShip,
victim = deathData.VictimPilot,
enlisted = enemyPlayerData?.JoinDate,
rsi = enemyPlayerData?.UEERecord,
weapon = deathData.Weapon,
method = deathData.DamageType,
victim_ship = killData.EnemyShip,
victim = killData.EnemyPilot,
enlisted = killData.Enlisted,
rsi = killData.RecordNumber,
weapon = killData.Weapon,
method = killData.Method,
// loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
game_version = LocalPlayerData.GameVersion ?? "Unknown",
trackr_version = UpdatePage.currentVersion.Replace("v", "") ?? "Unknown",
location = LocalPlayerData.LastSeenVehicleLocation ?? "Unknown"
loadout_ship = killData.Ship,
game_version = killData.GameVersion,
trackr_version = killData.TrackRver,
location = "Unknown"
};
switch (LocalPlayerData.CurrentGameMode)
{
case GameMode.PersistentUniverse:
killData.gamemode = "pu";
break;
case GameMode.ArenaCommander:
killData.gamemode = "ac";
break;
}
var httpClient = new HttpClient();
string jsonData = JsonSerializer.Serialize(killData);
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + ConfigManager.ApiKey);