コード例 #1
0
ファイル: NewPages.cs プロジェクト: Claymore/WikiBots
 public NewPages(PortalModule module,
                 IEnumerable<string> categories,
                 IEnumerable<string> categoriesToIgnore,
                 IEnumerable<string> usersToIgnore,
                 string page,
                 int ns,
                 int depth,
                 int hours,
                 int maxItems,
                 string format,
                 string delimeter,
                 string header,
                 string footer,
                 bool markEdits)
 {
     _categories = new List<string>(categories);
     _categoriesToIgnore = new List<string>(categoriesToIgnore);
     _usersToIgnore = new HashSet<string>(usersToIgnore);
     Page = page;
     MaxItems = maxItems;
     Format = format.Replace("%(название)", "{0}").Replace("%(автор)", "{1}").Replace("%(дата)", "{2}");
     Hours = hours;
     Module = module;
     Delimeter = delimeter;
     Depth = depth;
     Header = header;
     Footer = footer;
     Namespace = ns;
     MarkEdits = markEdits;
 }
コード例 #2
0
 public CategoryTemplateIntersection(PortalModule module,
                 IEnumerable<string> categories,
                 IEnumerable<string> categoriesToIgnore,
                 string templates,
                 string page,
                 int ns,
                 int depth,
                 int hours,
                 int maxItems,
                 string format,
                 string delimeter,
                 string header,
                 string footer,
                 bool markEdits)
     : base(module,
            categories,
            categoriesToIgnore,
            new string[] {},
            page,
            ns,
            depth,
            hours,
            maxItems,
            format,
            delimeter,
            header,
            footer,
            markEdits)
 {
     Templates = templates;
 }
コード例 #3
0
 public NewPagesWithWeeks(PortalModule module,
                 IEnumerable<string> categories,
                 IEnumerable<string> categoriesToIgnore,
                 string page,
                 int ns,
                 int depth,
                 int maxItems,
                 string format,
                 string delimeter,
                 string header,
                 string footer,
                 bool markEdits)
     : base(module,
            categories,
            categoriesToIgnore,
            new string[] {},
            page,
            ns,
            depth,
            192,
            maxItems,
            format,
            delimeter,
            header,
            footer,
            markEdits)
 {
 }
コード例 #4
0
 public NewPagesWithImages(PortalModule module,
                 IEnumerable<string> categories,
                 IEnumerable<string> categoriesToIgnore,
                 string page,
                 int ns,
                 int depth,
                 int hours,
                 int maxItems,
                 string format,
                 string delimeter,
                 string header,
                 string footer,
                 Regex regex,
                 bool markEdits)
     : base(module,
            categories,
            categoriesToIgnore,
            new string[] {},
            page,
            ns,
            depth,
            hours,
            maxItems,
            format,
            delimeter,
            header,
            footer,
            markEdits)
 {
     Format = Format.Replace("%(имя файла)", "{1}");
     _regex = regex;
 }
コード例 #5
0
 public NewPagesWithArchive(PortalModule module,
                 IEnumerable<string> categories,
                 IEnumerable<string> categoriesToIgnore,
                 IEnumerable<string> usersToIgnore,
                 string page,
                 int ns,
                 string archive,
                 int depth,
                 int hours,
                 int maxItems,
                 string format,
                 string delimeter,
                 string header,
                 string footer,
                 bool markEdits)
     : base(module,
            categories,
            categoriesToIgnore,
            usersToIgnore,
            page,
            ns,
            depth,
            hours,
            maxItems,
            format,
            delimeter,
            header,
            footer,
            markEdits)
 {
     ArchivePage = archive;
 }
コード例 #6
0
ファイル: WatchList.cs プロジェクト: Claymore/WikiBots
 public WatchList(PortalModule module, string category, string page, int ns, string format, int depth)
 {
     Category = category;
     Format = format.Replace("{", "{{").Replace("}", "}}").Replace("%(название)", "{0}");
     Page = page;
     Depth = depth;
     Module = module;
     Namespace = ns;
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: Claymore/WikiBots
        public static bool TryParse(WikiPage page,
                                    string directory,
                                    PortalModule portal,
                                    out IPortalModule module)
        {
            module = null;
            Dictionary<string, string> options;
            if (!TryParseTemplate(page.Text, out options))
            {
                return false;
            }

            var categories = new List<string>();
            if (options.ContainsKey("категория"))
            {
                categories.Add(options["категория"]);
            }

            if (options.ContainsKey("категории"))
            {
                string[] separators;
                if (options["категории"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["категории"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        categories.Add(cat);
                    }
                }
            }

            var categoriesToIgnore = new List<string>();
            if (options.ContainsKey("игнорировать"))
            {
                string[] separators;
                if (options["игнорировать"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["игнорировать"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        categoriesToIgnore.Add(cat);
                    }
                }
            }

            var usersToIgnore = new List<string>();
            if (options.ContainsKey("игнорировать авторов"))
            {
                string[] separators;
                if (options["игнорировать авторов"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["игнорировать авторов"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        usersToIgnore.Add(cat);
                    }
                }
            }

            string title = "";
            if (options.ContainsKey("страница"))
            {
                title = options["страница"];
            }

            string archive = "";
            if (options.ContainsKey("архив"))
            {
                archive = options["архив"];
            }

            string prefix = "";
            if (options.ContainsKey("префикс"))
            {
                prefix = options["префикс"];
            }

            bool markEdits = true;
            if (options.ContainsKey("помечать правки") && options["помечать правки"].ToLower() == "нет")
            {
                markEdits = false;
            }

            int ns = 0;
            if (options.ContainsKey("пространство имён"))
            {
                int.TryParse(options["пространство имён"], out ns);
            }

            string header = "";
            if (options.ContainsKey("шапка"))
            {
                header = options["шапка"].Replace("\\n", "\n");
            }

            string footer = "";
            if (options.ContainsKey("подвал"))
            {
                footer = options["подвал"].Replace("\\n", "\n");
            }

            string templates = "";
            if (options.ContainsKey("шаблоны"))
            {
                templates = options["шаблоны"].Replace("\\n", "\n");
            }

            string format = "* [[%(название)]]";
            if (options.ContainsKey("формат элемента"))
            {
                format = options["формат элемента"].Replace("{", "{{").Replace("}", "}}");
            }

            int depth = 15;
            if (options.ContainsKey("глубина"))
            {
                int.TryParse(options["глубина"], out depth);
            }

            int hours = 720;
            if (options.ContainsKey("часов"))
            {
                int.TryParse(options["часов"], out hours);
            }

            int maxItems = 20;
            if (options.ContainsKey("элементов"))
            {
                int.TryParse(options["элементов"], out maxItems);
            }

            int normalSize = 40 * 1000;
            if (options.ContainsKey("нормальная"))
            {
                int.TryParse(options["нормальная"], out normalSize);
            }

            int shortSize = 10 * 1000;
            if (options.ContainsKey("небольшая"))
            {
                int.TryParse(options["небольшая"], out shortSize);
            }

            string longColor = "#F2FFF2";
            if (options.ContainsKey("цвет крупной"))
            {
                longColor = options["цвет крупной"];
            }

            string shortColor = "#FFE8E9";
            if (options.ContainsKey("цвет небольшой"))
            {
                archive = options["цвет небольшой"];
            }

            string normalColor = "#FFFDE8";
            if (options.ContainsKey("цвет нормальной"))
            {
                archive = options["цвет нормальной"];
            }

            string delimeter = "\n";
            if (options.ContainsKey("разделитель"))
            {
                delimeter = options["разделитель"].Replace("\"", "").Replace("\\n", "\n");
            }

            if (options.ContainsKey("тип"))
            {
                string t = options["тип"].ToLower();
                if (t == "список новых статей")
                {
                    if (!options.ContainsKey("архив"))
                    {
                        module = new NewPages(portal,
                            categories,
                            categoriesToIgnore,
                            usersToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                    }
                    else
                    {
                        module = new NewPagesWithArchive(portal,
                            categories,
                            categoriesToIgnore,
                            usersToIgnore,
                            title,
                            ns,
                            archive,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                    }
                }
                else if (t == "список наблюдения")
                {
                    module = new WatchList(portal,
                        categories[0],
                        title,
                        ns,
                        format,
                        depth);
                }
                else if (t == "отсортированный список статей, которые должны быть во всех проектах")
                {
                    module = new EncyShell(portal,
                        title,
                        shortSize,
                        normalSize,
                        shortColor,
                        normalColor,
                        longColor);
                }
                else if (t == "список новых статей с изображениями в карточке")
                {
                    module = new NewPagesWithImages(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список новых статей с изображениями")
                {
                    Regex regex = new Regex(@"\[{2}(Image|File|Файл|Изображение):(?'fileName'.+?)\|");
                    module = new NewPagesWithImages(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            regex,
                            markEdits);
                }
                else if (t == "списки новых статей по дням")
                {
                    module = new NewPagesWithWeeks(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список страниц с заданными категориями и шаблонами")
                {
                    module = new CategoryTemplateIntersection(portal,
                            categories,
                            categoriesToIgnore,
                            templates,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список страниц с заданными категориями, шаблонами и обсуждением")
                {
                    module = new CategoryIntersectionAndTalkPages(portal,
                            categories,
                            categoriesToIgnore,
                            templates,
                            prefix,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
            }
            return module != null;
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Claymore/WikiBots
        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;
        }