Created
December 21, 2021 11:43
-
-
Save AlRado/e8d8bd7e9ea368840dd2f9c63e612ac2 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 hidden or 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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "dotnet_interactive": { | |
| "language": "csharp" | |
| } | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "using System.Collections.Generic;\n", | |
| "using System.Linq;\n", | |
| "using Microsoft.DotNet.Interactive;\n", | |
| "using Microsoft.DotNet.Interactive.Formatting;\n", | |
| "using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;\n", | |
| "\n", | |
| "void downloadAndShowImages(params string[] urls) {\n", | |
| " display(span(urls.Select(url => \n", | |
| " img[src:url, style:\"height:10em; padding: 4px\", title:\"Downloaded image\", alt: \"Loading error\"]))\n", | |
| " );\n", | |
| "}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "dotnet_interactive": { | |
| "language": "csharp" | |
| } | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "using System;\n", | |
| "using System.Net.Http;\n", | |
| "using System.IO;\n", | |
| "using Newtonsoft.Json;\n", | |
| "using Newtonsoft.Json.Linq;\n", | |
| "\n", | |
| "async Task<string> getTopZxScreens(int limit) {\n", | |
| " var httpClient = new HttpClient();\n", | |
| " var httpResponse = await httpClient.GetAsync(\n", | |
| " $\"https://zxart.ee/api/types:zxPicture/export:zxPicture/language:eng/start:0/limit:{limit}/order:votes,desc/filter:zxPictureAll=1;\");\n", | |
| " return await httpResponse.Content.ReadAsStringAsync();\n", | |
| "}\n", | |
| "\n", | |
| "string[] getScreensUrls(string jsonData) {\n", | |
| " var jObject = JsonConvert.DeserializeObject<JObject>(jsonData);\n", | |
| " return jObject.Value<JObject>(\"responseData\").\n", | |
| " Value<JArray>(\"zxPicture\").Select(x => x.Value<string>(\"imageUrl\")).ToArray();\n", | |
| "}\n", | |
| "\n", | |
| "string[] getTopZxScreensUrls(int limit) {\n", | |
| " var topZxScreensResponse = getTopZxScreens(limit).Result;\n", | |
| " return getScreensUrls(topZxScreensResponse);\n", | |
| "}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "dotnet_interactive": { | |
| "language": "csharp" | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<span><img src=\"https://zxart.ee/zxscreen/border:0/mode:mix/pal:srgb/type:standard/zoom:1/id:84933/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img><img src=\"https://zxart.ee/zxscreen/border:0/mode:mix/pal:srgb/type:standard/zoom:1/id:47111/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img><img src=\"https://zxart.ee/zxscreen/border:0/mode:mix/pal:srgb/type:standard/zoom:1/id:44968/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img><img src=\"https://zxart.ee/zxscreen/border:0/mode:mix/pal:srgb/type:standard/zoom:1/id:45313/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img><img src=\"https://zxart.ee/zxscreen/border:1/mode:mix/pal:srgb/type:standard/zoom:1/id:54076/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img><img src=\"https://zxart.ee/zxscreen/border:0/mode:mix/pal:srgb/type:standard/zoom:1/id:81451/\" style=\"height:10em; padding: 4px\" title=\"Downloaded image\" alt=\"Loading error\"></img></span>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "var limit = 6;\n", | |
| "downloadAndShowImages(getTopZxScreensUrls(limit));" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "interpreter": { | |
| "hash": "a17440ef529219f80c0c11158b97dd17cc1c283d34abc79fc3eddfee85d20b70" | |
| }, | |
| "kernelspec": { | |
| "display_name": ".NET (C#)", | |
| "language": "C#", | |
| "name": ".net-csharp" | |
| }, | |
| "language_info": { | |
| "file_extension": ".cs", | |
| "mimetype": "text/x-csharp", | |
| "name": "C#", | |
| "pygments_lexer": "csharp", | |
| "version": "9.0" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment