Vai al contenuto

Utente:GryffindorD/Ricerca per Wiki

Da Wikiquote, aforismi e citazioni in libertà.
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = true;
            Summary = "test";
            string link = @"https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=itwikiquote&titles=" + ArticleTitle + "&props=sitelinks";
            
            System.Net.WebClient client = new System.Net.WebClient();
            System.IO.Stream data = client.OpenRead(link);
            System.IO.StreamReader reader = new System.IO.StreamReader(data, Encoding.UTF8);
            string result = reader.ReadToEnd();
            result=System.Text.RegularExpressions.Regex.Unescape(result);

            string pattern = @"""site"":""itwiki"",""title"":""(.[^"""",]+)""";
            Regex regex = new Regex(pattern, RegexOptions.Multiline);

            Match match = regex.Match(result);
            if (match.Success)
            {
                string res = "* [[" + ArticleTitle + "]] - [[:w:" + match.Groups[1].Value + "]]";
                System.IO.File.AppendAllText(@"D:\Wikipedia\Lista.txt", res + Environment.NewLine, Encoding.UTF8);
            }    
            return ArticleText;
        }