User:Dixtosa/addMissingPoem
Appearance
Site s = new Site("https://wikisource.org", "Dixtosa", password);
PageList pl = new PageList(s);
pl.FillFromSearchResults(@"insource:/\<poem\>/ incategory:Mingrelian -insource:/\<\/poem\>/", 400);
foreach (var page in pl)
{
Page p = (Page)page;
p.Load();
string t = p.text;
t = Regex.Replace(t, @"\|\s*noauthor\s*=\s*\[\[\s*(.+)\s*\]\]", "|author = ${1}");
if (t.IndexOf("</poem>") >= 0) throw new System.Exception();
int poemIndex = t.IndexOf("<poem>");
int pos = t.IndexOf("[[Category", poemIndex);
pos--;
while (t[pos] == '\n' || t[pos] == ' ') pos--;
pos++;
t = t.Insert(pos, "\n</poem>");
p.text = t;
p.watched = true;
p.Save("Adding missing </poem> and converting noauthor to author", true);
}