Chaged colors
Added handelrs for networking exceptions Made Book selector a bit bigger Fixed issue with publishing date
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user