public async Task <string> GetUrl() { int nowDay = DateTime.Now.Day; if (nowDay == lastDay) { return(urlCache); } else { try { string url = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"; using HttpClient httpClient = new() { Timeout = TimeSpan.FromSeconds(5) }; string jsonStr = await httpClient.GetStringAsync(url); BingWallpaper wallpaper = JsonSerializer.Deserialize <BingWallpaper>(jsonStr); urlCache = "https://www.bing.com/" + wallpaper.images[0].url; lastDay = nowDay; return(urlCache); } catch (Exception) { return(null); } } }
public Wallpaper DecodeWallpaper(JToken imageJToken) { var todayWallpaper = new BingWallpaper() { UrlBase = (string)imageJToken["urlbase"] }; todayWallpaper.Transform(new Wallpaper.ResolutionValue() { Width = 1920, Height = 1080 }); return(todayWallpaper); }
static void Main(string[] args) { var bingWallpaper = new BingWallpaper(); bingWallpaper.SetBingWallpaper(); }