-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWikiAccessSample.cs
More file actions
94 lines (76 loc) · 2.83 KB
/
WikiAccessSample.cs
File metadata and controls
94 lines (76 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WikiAccess
{
class WikiAccessSample
{
static void Main(string[] args)
{
int Qcode = 15818798;
WikidataIO WIO = new WikidataIO();
WIO.Action = "wbgetentities";
WIO.Format = "json";
WIO.Sites = "";
WIO.Ids = Qcode;
WIO.Props = "claims|descriptions|labels|sitelinks";
WIO.Languages = "";
WIO.ClaimsRequired = new string[5] { "P31", "P27", "P21", "P569", "P570" };
WikidataFields Fields = WIO.GetData();
Console.WriteLine("-----Errors-----");
List<ErrorLog> Errors = new List<ErrorLog>();
Errors = WIO.GetErrors();
foreach (ErrorLog thisLog in Errors)
{
if (thisLog != null)
{
foreach (ErrorMessage Error in thisLog.Errors)
{
Console.WriteLine(Error.ToString());
}
}
}
if (Fields == null)
return;
string ThisName;
if (!Fields.Labels.TryGetValue("en-gb", out ThisName))
Fields.Labels.TryGetValue("en", out ThisName);
string ThisDescription;
if (!Fields.Description.TryGetValue("en-gb", out ThisDescription))
Fields.Description.TryGetValue("en", out ThisDescription);
string ThisWikipedia;
Fields.WikipediaLinks.TryGetValue("enwiki", out ThisWikipedia);
Console.WriteLine(ThisName);
Console.WriteLine(ThisDescription);
Console.WriteLine("====================");
WikipediaIO WPIO = new WikipediaIO();
WPIO.Action = "query";
WPIO.Export = "Yes";
WPIO.ExportNoWrap = "Yes";
WPIO.Format = "xml";
WPIO.Redirects = "yes";
WPIO.Titles = ThisWikipedia;
if (WPIO.GetData())
{
List<string[]> Templates = WPIO.TemplatesUsed;
List<string> Categories = WPIO.CategoriesUsed;
Console.WriteLine(WPIO.PageTitle);
Console.WriteLine(Templates.Count().ToString() + " templates");
Console.WriteLine(Categories.Count().ToString() + " categories");
}
List<ErrorLog> Errors2 = new List<ErrorLog>();
Errors2 = WPIO.GetErrors();
foreach (ErrorLog thisLog in Errors2)
{
if (thisLog != null)
{
foreach (ErrorMessage Error in thisLog.Errors)
{
Console.WriteLine(Error.ToString());
}
}
}
}
}
}