From 4def11c2f9eb6890643c1b58522547d500589f8d Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sat, 27 May 2023 12:55:12 -0400 Subject: [PATCH] started wikidata component --- .../BirdsiteLive.Wikidata.csproj | 10 ++++++++ src/BirdsiteLive.Wikidata/Program.cs | 23 +++++++++++++++++++ src/BirdsiteLive.Wikidata/README.md | 2 ++ src/BirdsiteLive.Wikidata/query.sparql | 9 ++++++++ src/BirdsiteLive.sln | 7 ++++++ 5 files changed, 51 insertions(+) create mode 100644 src/BirdsiteLive.Wikidata/BirdsiteLive.Wikidata.csproj create mode 100644 src/BirdsiteLive.Wikidata/Program.cs create mode 100644 src/BirdsiteLive.Wikidata/README.md create mode 100644 src/BirdsiteLive.Wikidata/query.sparql diff --git a/src/BirdsiteLive.Wikidata/BirdsiteLive.Wikidata.csproj b/src/BirdsiteLive.Wikidata/BirdsiteLive.Wikidata.csproj new file mode 100644 index 0000000..2b14c81 --- /dev/null +++ b/src/BirdsiteLive.Wikidata/BirdsiteLive.Wikidata.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/src/BirdsiteLive.Wikidata/Program.cs b/src/BirdsiteLive.Wikidata/Program.cs new file mode 100644 index 0000000..1b861e4 --- /dev/null +++ b/src/BirdsiteLive.Wikidata/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using System.Xml; + +Console.WriteLine("Hello, World!"); +var client = new HttpClient(); +string query = new StreamReader("query.sparql").ReadToEnd(); + +client.DefaultRequestHeaders.Add("Accept", "text/csv"); +client.DefaultRequestHeaders.Add("User-Agent", "BirdMakeup/1.0 (https://bird.makeup; coolbot@example.org) BirdMakeup/1.0"); +var response = await client.GetAsync($"https://query.wikidata.org/sparql?query={Uri.EscapeDataString(query)}"); +var content = await response.Content.ReadAsStringAsync(); + +// Console.WriteLine(content); + +foreach (string n in content.Split("\n")) +{ + var s = n.Split(","); + Console.WriteLine(s[0]); +} + diff --git a/src/BirdsiteLive.Wikidata/README.md b/src/BirdsiteLive.Wikidata/README.md new file mode 100644 index 0000000..fd05dfd --- /dev/null +++ b/src/BirdsiteLive.Wikidata/README.md @@ -0,0 +1,2 @@ +# Wikidata service + diff --git a/src/BirdsiteLive.Wikidata/query.sparql b/src/BirdsiteLive.Wikidata/query.sparql new file mode 100644 index 0000000..61c97fa --- /dev/null +++ b/src/BirdsiteLive.Wikidata/query.sparql @@ -0,0 +1,9 @@ +#Cats +SELECT ?item ?username ?username2 ?linkcount ?itemLabel +WHERE +{ + ?item wdt:P2002 ?username. + ?item wdt:P4033 ?username2. + ?item wikibase:sitelinks ?linkcount . + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language +} ORDER BY DESC(?linkcount) LIMIT 5000 \ No newline at end of file diff --git a/src/BirdsiteLive.sln b/src/BirdsiteLive.sln index 77a6067..b219ca3 100644 --- a/src/BirdsiteLive.sln +++ b/src/BirdsiteLive.sln @@ -49,6 +49,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Common.Tests", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Twitter.Tests", "Tests\BirdsiteLive.Twitter.Tests\BirdsiteLive.Twitter.Tests.csproj", "{2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Wikidata", "BirdsiteLive.Wikidata\BirdsiteLive.Wikidata.csproj", "{EAB43087-359C-46BD-8796-5F7D9B473B39}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -131,6 +133,10 @@ Global {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Debug|Any CPU.Build.0 = Debug|Any CPU {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Release|Any CPU.ActiveCfg = Release|Any CPU {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Release|Any CPU.Build.0 = Release|Any CPU + {EAB43087-359C-46BD-8796-5F7D9B473B39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EAB43087-359C-46BD-8796-5F7D9B473B39}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -154,6 +160,7 @@ Global {0A311BF3-4FD9-4303-940A-A3778890561C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {C69F7582-6050-44DC-BAAB-7C8F0BDA525C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} + {EAB43087-359C-46BD-8796-5F7D9B473B39} = {DA3C160C-4811-4E26-A5AD-42B81FAF2D7C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}