Chaged colors

Added handelrs for networking exceptions
Made Book selector a bit bigger
Fixed issue with publishing date
This commit is contained in:
2025-02-04 09:03:10 +01:00
parent 13c26eb3d8
commit 3c44c8dc8a
8 changed files with 84 additions and 38 deletions

View File

@@ -1,5 +1,7 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
namespace Bokhantarare;
@@ -46,7 +48,7 @@ public class Book
}
Dictionary<String, Object>? responce = JsonSerializer.Deserialize<Dictionary<String, Object>>(
Helper.Request($"https://openlibrary.org/api/books?bibkeys=ISBN:{ISBN}&jscmd=details&format=json"));
Helper.Request($"https://openlibrary.org/api/books?bibkeys=ISBN:{ISBN}&jscmd=details&format=json") ?? throw new Exception("Network Error"));
if (responce == null)
{
@@ -86,7 +88,16 @@ public class Book
string pubDate = "";
if (details.ContainsKey("publish_date"))
{
details["publish_date"].ToString();
pubDate = details["publish_date"].ToString();
if (!Regex.IsMatch(pubDate, @"^\d{4}$"))
{
if (DateTime.TryParse(pubDate, CultureInfo.InvariantCulture, DateTimeStyles.None,
out DateTime date))
{
pubDate = date.ToString("yyyy");
}
}
}
else
{
@@ -100,7 +111,7 @@ public class Book
title = title.Trim();
Dictionary<String, Object>? responce = JsonSerializer.Deserialize<Dictionary<String, Object>>(
Helper.Request($"https://openlibrary.org/search.json?q={title}"));
Helper.Request($"https://openlibrary.org/search.json?q={title}") ?? throw new Exception("Network Error"));
if (responce == null)
{