Created
December 21, 2021 11:45
-
-
Save AlRado/69bf9190a5cebfc272c8ba0547b719c5 to your computer and use it in GitHub Desktop.
Downloads and displays top ZX-Spectrum images from the site https://zxart.ee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!csharp | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.DotNet.Interactive; | |
using Microsoft.DotNet.Interactive.Formatting; | |
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags; | |
void downloadAndShowImages(params string[] urls) { | |
display(span(urls.Select(url => | |
img[src:url, style:"height:10em; padding: 4px", title:"Downloaded image", alt: "Loading error"])) | |
); | |
} | |
#!csharp | |
using System; | |
using System.Net.Http; | |
using System.IO; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
async Task<string> getTopZxScreens(int limit) { | |
var httpClient = new HttpClient(); | |
var httpResponse = await httpClient.GetAsync( | |
$"https://zxart.ee/api/types:zxPicture/export:zxPicture/language:eng/start:0/limit:{limit}/order:votes,desc/filter:zxPictureAll=1;"); | |
return await httpResponse.Content.ReadAsStringAsync(); | |
} | |
string[] getScreensUrls(string jsonData) { | |
var jObject = JsonConvert.DeserializeObject<JObject>(jsonData); | |
return jObject.Value<JObject>("responseData"). | |
Value<JArray>("zxPicture").Select(x => x.Value<string>("imageUrl")).ToArray(); | |
} | |
string[] getTopZxScreensUrls(int limit) { | |
var topZxScreensResponse = getTopZxScreens(limit).Result; | |
return getScreensUrls(topZxScreensResponse); | |
} | |
#!csharp | |
var limit = 6; | |
downloadAndShowImages(getTopZxScreensUrls(limit)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment