Last active
October 3, 2018 17:48
-
-
Save xubiod/3d470833ae4bebfeb3a8fb3ffe234c28 to your computer and use it in GitHub Desktop.
example of the api done in rextester
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
| //Rextester.Program.Main is the entry point for your code. Don't change it. | |
| //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text.RegularExpressions; | |
| using Newtonsoft.Json.Linq; | |
| using System.ComponentModel; | |
| using System.Net; | |
| namespace Rextester | |
| { | |
| public class Program | |
| { | |
| private static WebClient wb = new WebClient(); | |
| /* | |
| Console input looks like this | |
| // WITH TO PARAM | |
| Nintendo | |
| NintendoSwitch | |
| 20 | |
| get first 20 pages from "Nintendo" to "NintendoSwitch" | |
| // WITHOUT TO PARAM | |
| Atari | |
| 50 | |
| get first 20 pages from "Atari" to infinity | |
| */ | |
| public static void Main(string[] args) | |
| { | |
| Console.WriteLine("Wikipedia API Test\n\n"); | |
| Console.Write("Search-From>> "); | |
| string input = Console.ReadLine(); | |
| Console.Write("Search-To>> "); | |
| string input2 = Console.ReadLine(); | |
| Console.Write("Limit>> "); | |
| int limit = Math.Min(int.Parse(Console.ReadLine()), 500); | |
| string link; | |
| if (input2 == "") { | |
| Console.WriteLine("\n\nUsing API to find the first " + limit.ToString() + " pages about \"" + input + "\"\n\n"); | |
| link = "https://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=" + input + "&aplimit=" + limit.ToString() + "&format=json"; | |
| } else { | |
| Console.WriteLine("\n\nUsing API to find the first " + limit.ToString() + " pages about \"" + input + "\" to \"" + input2+ "\"\n\n"); | |
| link = "https://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=" + input + "&apto=" + input2 + "&aplimit=" + limit.ToString() + "&format=json"; | |
| } | |
| Console.WriteLine("Downloading..."); | |
| string data = wb.DownloadString(link); | |
| Console.WriteLine("Downloaded."); | |
| Console.WriteLine("Parsing..."); | |
| dynamic json_data = JObject.Parse(data); | |
| Console.WriteLine("Parsed.\n\n"); | |
| Console.WriteLine("Amount: " + json_data.query.allpages.Count.ToString()); | |
| string allTitles = ""; | |
| foreach(var item in json_data.query.allpages) { | |
| allTitles += item.title + " (" + item.pageid.ToString() + ")\n"; | |
| } | |
| Console.WriteLine("\n" + allTitles); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment