static int Main(string[] args) { if (args.Length < 2) { Console.Out.WriteLine("NewPagesWikiBot <language> <update comment>"); return 0; } string path = @"Cache\" + args[0] + @"\"; Directory.CreateDirectory(@"Cache\" + args[0]); Wiki wiki = new Wiki(string.Format("http://{0}.wikipedia.org/w/", args[0])); wiki.SleepBetweenQueries = 5; if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return 0; } Console.Out.WriteLine("Logging in as " + Settings.Default.Login + " to " + wiki.Uri + "..."); try { string cookieFile = @"Cache\" + args[0] + @"\cookie.jar"; WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password, cookieFile); string namespacesFile = @"Cache\" + args[0] + @"\namespaces.dat"; if (!WikiCache.LoadNamespaces(wiki, namespacesFile)) { wiki.GetNamespaces(); WikiCache.CacheNamespaces(wiki, namespacesFile); } } catch (WikiException e) { Console.Out.WriteLine(e.Message); return 0; } Console.Out.WriteLine("Logged in as " + wiki.User + "."); PortalModule portal = new PortalModule(args[0], args[1]); Directory.CreateDirectory("Cache\\" + args[0] + "\\NewPages\\"); Directory.CreateDirectory("Cache\\" + args[0] + "\\PagesInCategory\\"); Directory.CreateDirectory("Cache\\" + args[0] + "\\PagesInCategoryWithTemplates\\"); Cache.PurgeCache(args[0]); if (!File.Exists("Cache\\" + args[0] + "\\processed.txt")) { FileStream stream = File.Create("Cache\\" + args[0] + "\\processed.txt"); stream.Close(); } HashSet<string> processedPages = new HashSet<string>(); using (StreamReader sr = new StreamReader("Cache\\" + args[0] + "\\processed.txt")) { String line; while ((line = sr.ReadLine()) != null) { processedPages.Add(line); } } ParameterCollection parameters = new ParameterCollection() { { "generator", "embeddedin" }, { "geititle", "User:ClaymoreBot/Новые статьи" }, { "geilimit", "max" }, { "prop", "info" }, { "intoken", "edit" }, { "redirects", "1" } }; List<string> pages = new List<string>(); XmlDocument doc = wiki.Enumerate(parameters, true); foreach (XmlNode node in doc.SelectNodes("//page")) { string title = node.Attributes["title"].Value; pages.Add(title); } pages.Sort(); for (int i = 0; i < pages.Count; ++i) { try { if (processedPages.Contains(pages[i])) { continue; } WikiPage page = Cache.Load(wiki, pages[i], path); IPortalModule module; if (TryParse(page, path, portal, out module)) { module.Update(wiki); using (StreamWriter sw = new StreamWriter("Cache\\" + args[0] + "\\processed.txt", true)) { sw.WriteLine(pages[i]); } } } catch (WikiException) { return -1; } catch (System.Net.WebException) { return -1; } } File.Delete("Cache\\" + args[0] + "\\processed.txt"); Console.Out.WriteLine("Done."); return 0; }
private static bool UpdateUkWiki() { if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return false; } Wiki wiki = new Wiki("http://uk.wikipedia.org/w/"); wiki.SleepBetweenQueries = 2; Console.Out.WriteLine("Logging in as " + Settings.Default.Login + " to " + wiki.Uri + "..."); try { Directory.CreateDirectory(@"Cache\uk"); string cookieFile = @"Cache\uk\cookie.jar"; WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password, cookieFile); if (!WikiCache.LoadNamespaces(wiki, @"Cache\uk\namespaces.dat")) { wiki.GetNamespaces(); WikiCache.CacheNamespaces(wiki, @"Cache\uk\namespaces.dat"); } } catch (WikiException e) { Console.Out.WriteLine(e.Message); return false; } Console.Out.WriteLine("Logged in as " + Settings.Default.Login + "."); ArticlesForDeletionLocalization l10i = new ArticlesForDeletionLocalization(); l10i.Category = "Категорія:Незавершені обговорення вилучення сторінок"; l10i.Culture = "uk-UA"; l10i.MainPage = "Вікіпедія:Статті-кандидати на вилучення"; l10i.Template = "Вилучення статей"; l10i.TopTemplate = "/шапка"; l10i.BottomTemplate = "/низ"; l10i.Results = new string[] { "Підсумок" }; l10i.Language = "uk"; l10i.MainPageUpdateComment = "оновлення даних"; l10i.ArchiveTemplate = "Статті, винесені на вилучення"; l10i.ArchivePage = "Вікіпедія:Архів запитів на вилучення/"; l10i.EmptyArchive = "обговорення не розпочато"; l10i.Processor = RemoveVotes; l10i.StrikeOutComment = "закреслення заголовків"; l10i.AutoResultMessage = "Сторінка була вилучена {1} адміністратором [[User:{0}|]]. Була вказана наступна причина: «{2}». Це повідомлення було автоматично згенеровано ботом ~~~~.\n"; l10i.DateFormat = "d MMMM yyyy"; l10i.AutoResultComment = ", підбиття підсумків"; l10i.AutoResultSection = "Підсумок"; l10i.NotificationTemplate = "Залишено"; l10i.EmptyResult = "Підсумок"; l10i.ChallengedResult = "Оспоренный итог"; l10i.ArchiveHeader = "{| class=standard\n|-\n!| Дата\n!|" + l10i.ArchiveTemplate + "\n|-\n"; l10i.ArchiveFooter = "|}"; Cleanup.Localization cleanupL10i = new Cleanup.Localization(); cleanupL10i.Language = "uk"; cleanupL10i.Category = "Категорія:Вікіпедія:Незакриті обговорення поліпшення статей"; cleanupL10i.MainPage = "Вікіпедія:Статті, що необхідно поліпшити"; cleanupL10i.Culture = CultureInfo.CreateSpecificCulture("uk-UA"); cleanupL10i.Template = "Поліпшення статей"; cleanupL10i.TopTemplate = "/шапка"; cleanupL10i.BottomTemplate = "/низ"; cleanupL10i.Processor = RemoveOK; cleanupL10i.MainPageUpdateComment = "оновлення даних"; cleanupL10i.closedRE = new Regex(@"({{ВППОЛ-навігація}}\s*({{Закрито|Closed|закрито|closed)}})|({{(Закрито|Closed|закрито|closed)}}\s*{{ВППОЛ-навігація}})"); cleanupL10i.CloseComment = "закрито"; cleanupL10i.ClosePage = ClosePageUk; cleanupL10i.MainPageSection = "0"; cleanupL10i.ArchiveTemplate = "Статті, що необхідно поліпшити"; cleanupL10i.ArchivePage = "Вікіпедія:Статті, що необхідно поліпшити/Архів/"; cleanupL10i.EmptyArchive = "обговорення не розпочато"; cleanupL10i.NavigationTemplate = "ВППОЛ-навігація"; cleanupL10i.ArchiveHeader = "{| class=standard\n|-\n!| Дата\n!|" + cleanupL10i.ArchiveTemplate + "\n|-\n"; cleanupL10i.ArchiveFooter = "|}"; List<IModule> modules = new List<IModule>() { new Cleanup(cleanupL10i), new ArticlesForDeletion(l10i), }; for (int i = 0; i < modules.Count; ++i) { try { modules[i].Run(wiki); } catch (WikiException) { return false; } catch (WebException) { return false; } } Console.Out.WriteLine("Done."); return true; }
static int Main(string[] args) { if (args.Length < 3) { Console.Out.WriteLine("ArchiveWikiBot <language> <culture> <update comment>"); return 0; } if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return 0; } string path = @"Cache\" + args[0] + @"\"; Directory.CreateDirectory(@"Cache\" + args[0]); Wiki wiki = new Wiki(string.Format("http://{0}.wikipedia.org/w/", args[0])); wiki.SleepBetweenQueries = 2; Console.Out.WriteLine("Logging in as " + Settings.Default.Login + " to " + wiki.Uri + "..."); try { string cookieFile = @"Cache\" + args[0] + @"\cookie.jar"; WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password, cookieFile); string namespacesFile = @"Cache\" + args[0] + @"\namespaces.dat"; if (!WikiCache.LoadNamespaces(wiki, namespacesFile)) { wiki.GetNamespaces(); WikiCache.CacheNamespaces(wiki, namespacesFile); } } catch (WikiException e) { Console.Out.WriteLine(e.Message); return 0; } Console.Out.WriteLine("Logged in as " + wiki.User + "."); L10i l10i = new L10i(args[0], args[1], args[2]); WikiPage listPage = new WikiPage("User:ClaymoreBot/Архивация/Список"); listPage.Load(wiki); StringReader reader = new StringReader(listPage.Text); HashSet<string> pages = new HashSet<string>(); Regex pageRE = new Regex(@"^\*\s*(.+)\s*$"); string line; while ((line = reader.ReadLine()) != null) { Match m = pageRE.Match(line); if (m.Success) { pages.Add(m.Groups[1].Value); } } ParameterCollection parameters = new ParameterCollection(); parameters.Add("generator", "embeddedin"); parameters.Add("geititle", "User:ClaymoreBot/Архивация"); parameters.Add("geilimit", "max"); parameters.Add("prop", "info"); parameters.Add("intoken", "edit"); parameters.Add("redirects"); XmlDocument doc = wiki.Enumerate(parameters, true); foreach (XmlNode node in doc.SelectNodes("//page")) { string title = node.Attributes["title"].Value; WikiPage page = Cache.Load(wiki, title, path); IArchive archive; try { if (TryParse(page, path, pages.Contains(page.Title), l10i, out archive)) { archive.Archivate(wiki); } } catch (WikiException) { } catch (Exception) { } } return 0; }
private static bool UpdateRuWiki() { if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return false; } Wiki wiki = new Wiki("http://ru.wikipedia.org/w/"); wiki.SleepBetweenQueries = 2; Console.Out.WriteLine("Logging in as " + Settings.Default.Login + " to " + wiki.Uri + "..."); try { Directory.CreateDirectory(@"Cache\ru"); string cookieFile = @"Cache\ru\cookie.jar"; WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password, cookieFile); if (!WikiCache.LoadNamespaces(wiki, @"Cache\ru\namespaces.dat")) { wiki.GetNamespaces(); WikiCache.CacheNamespaces(wiki, @"Cache\ru\namespaces.dat"); } } catch (WikiException e) { Console.Out.WriteLine(e.Message); return false; } Console.Out.WriteLine("Logged in as " + Settings.Default.Login + "."); string errorFileName = @"Cache\ru\Errors.txt"; Cleanup.Localization cleanupL10i = new Cleanup.Localization(); cleanupL10i.Language = "ru"; cleanupL10i.Category = "Категория:Википедия:Незакрытые обсуждения статей для улучшения"; cleanupL10i.MainPage = "Википедия:К улучшению"; cleanupL10i.Culture = CultureInfo.CreateSpecificCulture("ru-RU"); cleanupL10i.SectionTitle = "К улучшению"; cleanupL10i.Template = "Улучшение статей/День"; cleanupL10i.TopTemplate = "Улучшение статей/Статьи, вынесенные на улучшение"; cleanupL10i.BottomTemplate = "Википедия:К улучшению/Подвал"; cleanupL10i.Processor = RemoveOK; cleanupL10i.MainPageUpdateComment = "обновление"; cleanupL10i.closedRE = new Regex(@"({{ВПКУЛ-(Н|н)авигация}}\s*{{(Закрыто|Closed|закрыто|closed)}})|({{(Закрыто|Closed|закрыто|closed)}}\s*{{ВПКУЛ-(Н|н)авигация}})"); cleanupL10i.CloseComment = "обсуждение закрыто"; cleanupL10i.ClosePage = ClosePageRu; cleanupL10i.MainPageSection = "1"; cleanupL10i.ArchiveTemplate = "Статьи, вынесенные на улучшение"; cleanupL10i.ArchivePage = "Википедия:К улучшению/Архив/"; cleanupL10i.EmptyArchive = "нет обсуждений"; cleanupL10i.NavigationTemplate = "ВПКУЛ-Навигация"; cleanupL10i.ArchiveFooter = "{{Улучшение статей/Конец}}"; cleanupL10i.ArchiveHeader = "{{Навигация по архиву КУЛ}}\n{{Улучшение статей/Начало}}"; ArticlesForDeletionLocalization l10i = new ArticlesForDeletionLocalization(); l10i.Category = "Категория:Википедия:Незакрытые обсуждения удаления страниц"; l10i.Culture = "ru-RU"; l10i.MainPage = "Википедия:К удалению"; l10i.Template = "Удаление статей"; l10i.TopTemplate = "/Заголовок"; l10i.BottomTemplate = "/Подвал"; l10i.Results = new string[] { "Итог", "Общий итог", "Автоматический итог", "Автоитог" }; l10i.Language = "ru"; l10i.MainPageUpdateComment = "обновление"; l10i.ArchiveTemplate = "Статьи, вынесенные на удаление"; l10i.ArchivePage = "Википедия:Архив запросов на удаление/"; l10i.EmptyArchive = "нет обсуждений"; l10i.Processor = null; l10i.StrikeOutComment = "зачёркивание заголовков"; l10i.AutoResultMessage = "Страница была удалена {1} участником [[User:{0}|]]. Была указана следующая причина: «{2}». Данное сообщение было автоматически сгенерировано ботом ~~~~.\n"; l10i.DateFormat = "d MMMM yyyy в HH:mm (UTC)"; l10i.AutoResultComment = " и подведение итогов"; l10i.AutoResultSection = "Автоитог"; l10i.NotificationTemplate = "Оставлено"; l10i.EmptyResult = "Пустой итог"; l10i.ChallengedResult = "Оспоренный итог"; l10i.ArchiveHeader = "{{Навигация по архиву КУ}}\n{{Удаление статей/Начало}}\n"; l10i.ArchiveFooter = "{{Удаление статей/Конец}}"; List<IModule> modules = new List<IModule>() { new CategoriesForDiscussion(), new DeletionReview(), new ProposedSplits(), new Cleanup(cleanupL10i), new ProposedMerges(), new ArticlesForDeletion(l10i), new IncubatorReview("Википедия:Проект:Инкубатор/Мини-рецензирование"), new IncubatorReview("Википедия:Проект:Инкубатор/Мини-рецензирование/Наука"), new IncubatorReview("Википедия:Проект:Инкубатор/Стабы"), new RequestedMoves() }; if (!File.Exists(errorFileName)) { using (FileStream stream = File.Create(errorFileName)) { } } int lastIndex = 0; using (TextReader streamReader = new StreamReader(errorFileName)) { string line = streamReader.ReadToEnd(); if (!string.IsNullOrEmpty(line)) { lastIndex = int.Parse(line); } } for (int i = lastIndex; i < modules.Count; ++i) { try { modules[i].Run(wiki); } catch (WikiException) { using (TextWriter streamWriter = new StreamWriter(errorFileName)) { streamWriter.Write(i); } return false; } catch (WebException) { using (TextWriter streamWriter = new StreamWriter(errorFileName)) { streamWriter.Write(i); } return false; } } if (File.Exists(errorFileName)) { File.Delete(errorFileName); } Console.Out.WriteLine("Done."); return true; }