Example #1
0
        public List <RevisionData> GetRevisions(string title, int revId = -1)
        {
            // returns the revisions for the given wikipedia page
            // title: the name of the wikipedia page what we are looking for
            // revId: the first revision id, we interested in

            string rvendid = revId > -1 ? "&rvendid=" + revId : "";
            //Console.WriteLine(apiLink + "&prop=revisions&titles=" + title + revisionProperties + rvendid + format + encoding);
            string url    = apiQueryLink + "&titles=" + title + revisionProperties + rvendid + format + encoding;
            string result = client.DownloadString(url);

            var revisions = new List <RevisionData>();

            try
            {
                var revisionsDict = JSONUtils.DeserializeRevisions(result);
                foreach (var entry in revisionsDict)
                {
                    int    eRevId     = (int)JSONUtils.GetValueFromJSONObject(entry, "revid");
                    int    eParentId  = (int)JSONUtils.GetValueFromJSONObject(entry, "parentid");
                    int    eSize      = (int)JSONUtils.GetValueFromJSONObject(entry, "size");
                    string eTimestamp = (string)JSONUtils.GetValueFromJSONObject(entry, "timestamp");
                    revisions.Add(new RevisionData(eRevId, eParentId, eSize, DateTime.ParseExact(eTimestamp, "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture)));
                }

                return(revisions);
            }
            catch (WikiAPIException exp)
            {
                return(revisions);
            }
        }
Example #2
0
        public string GetContent(string title, int revId = -1)
        {
            // returns the content of the given page
            // if revId not -1, then search by revId, otherwise search by title

            string cond   = revId > -1 ? "&revids=" + revId : "&titles=" + title;
            string result = client.DownloadString(apiQueryLink + cond + contentProperties + format + encoding);

            try
            {
                var revisions = JSONUtils.DeserializeRevisions(result);
                return((string)((Dictionary <string, object>)revisions.GetValue(0))["*"]);
            }
            catch (WikiAPIException exp)
            {
                return("Wrong wikipedia page.");
            }
        }