WikiCrawler/Tasks/Commons/PdOldAuto.cs
/// <summary>
/// Gets the year of death from the specified creator template.
/// </summary>
/// <param name="errcat">Error category that should be added to the creator.</param>
Gets the year of death from the specified creator template.
Gets the year of death from the specified creator template .
private static string GetCreatorDeathYear(Api commonsApi, Api wikidataApi,
			string creator)
		{
			creator = creator.Trim(s_CreatorTrim);
			if (s_CreatorToDeathYear.ContainsKey(creator))
			{
				return s_CreatorToDeathYear[creator];
			}
			else
			{
				Article article = commonsApi.GetPage(creator);
				if (!MediaWiki.Article.IsNullOrEmpty(article))
				{
					string wdDeathYear = "";
					string wdId = MediaWiki.WikiUtils.GetTemplateParameter("Wikidata", article.revisions[0].text);
					if (!string.IsNullOrEmpty(wdId))
					{
						Entity wikidata = wikidataApi.GetEntity(wdId);
						if (!wikidata.missing)
						{
							wdDeathYear = wikidata.GetClaimValueAsDate(MediaWiki.Wikidata.Prop_DateOfDeath).GetYear().ToString();
						}
					}
					string deathyear = MediaWiki.WikiUtils.GetTemplateParameter("Deathyear", article.revisions[0].text);
					if (string.IsNullOrEmpty(deathyear))
					{
						deathyear = MediaWiki.WikiUtils.GetTemplateParameter("Deathdate", article.revisions[0].text);
					}
					if (!string.IsNullOrEmpty(deathyear))
					{
						string[] datesplit = deathyear.Split('-');
						string year = datesplit[0];
						if (year.Length == 4
							&& char.IsDigit(year[0])
							&& char.IsDigit(year[1])
							&& char.IsDigit(year[2])
							&& char.IsDigit(year[3]))
						{
							s_CreatorToDeathYear[creator] = year;
							return year;
						}
						else
						{
							return wdDeathYear;
						}
					}
					else
					{
						Console.WriteLine("Creator '" + creator + "' has no deathdate.");
						return "";
					}
				}
				else
				{
					Console.WriteLine("Failed to get creator article.");
					return "";
				}
			}
		}
private static string GetCreatorDeathYear ( Api commonsApi , Api wikidataApi , string creator ) { creator = creator . Trim ( s_CreatorTrim ) ; if ( s_CreatorToDeathYear . ContainsKey ( creator ) ) { return s_CreatorToDeathYear [ creator ] ; } else { Article article = commonsApi . GetPage ( creator ) ; if ( ! MediaWiki . Article . IsNullOrEmpty ( article ) ) { string wdDeathYear = " " ; string wdId = MediaWiki . WikiUtils . GetTemplateParameter ( " " , article . revisions [ 0 ] . text ) ; if ( ! string . IsNullOrEmpty ( wdId ) ) { Entity wikidata = wikidataApi . GetEntity ( wdId ) ; if ( ! wikidata . missing ) { wdDeathYear = wikidata . GetClaimValueAsDate ( MediaWiki . Wikidata . Prop_DateOfDeath ) . GetYear ( ) . ToString ( ) ; } } string deathyear = MediaWiki . WikiUtils . GetTemplateParameter ( " " , article . revisions [ 0 ] . text ) ; if ( string . IsNullOrEmpty ( deathyear ) ) { deathyear = MediaWiki . WikiUtils . GetTemplateParameter ( " " , article . revisions [ 0 ] . text ) ; } if ( ! string . IsNullOrEmpty ( deathyear ) ) { string [ ] datesplit = deathyear . Split ( ' ' ) ; string year = datesplit [ 0 ] ; if ( year . Length == 4 && char . IsDigit ( year [ 0 ] ) && char . IsDigit ( year [ 1 ] ) && char . IsDigit ( year [ 2 ] ) && char . IsDigit ( year [ 3 ] ) ) { s_CreatorToDeathYear [ creator ] = year ; return year ; } else { return wdDeathYear ; } } else { Console . WriteLine ( " " + creator + " " ) ; return " " ; } } else { Console . WriteLine ( " " ) ; return " " ; } } }
Gets the year of death from the specified creator template.
Gets the year of death from the specified creator template .
//TODO: check against Wikidata and publicly report errors // check creator // get wikidata deathdate /*Console.WriteLine("Creator '" + creator + "' date '" + deathyear + "' malformed.");
							string cat = "Category:Creator templates with non-machine-readable birth/death dates";
							if (!Wikimedia.WikiUtils.HasCategory(cat, article.revisions[0].text))
							{
								article.revisions[0].text += "<noinclude>[[" + cat + "]]</noinclude>";
								commonsApi.SetPage(article, "(BOT) couldn't read deathdate", true, true);
							}*/
commonsApi
Api
wikidataApi
Api
creator
string
errcat
Error category that should be added to the creator.
Error category that should be added to the creator .