Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WikiEnv;
- using WikiEnv.Derived;
- using WikiEnv.Helpers;
- namespace WikiTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.UTF8;
- Wikibot wb = new Wikibot();
- Login.Log(wb, true);
- wb.Throttle = 3000;
- IDictionary<string, string> contentMap = wb.GetContentOfCategorymembers("Kategoria:phrasal verbs", LanguageCodes.EN);
- ICollection<string> workList = new List<string>(500);
- ICollection<string> exceptionList = new List<string>(50);
- foreach (var entry in contentMap)
- {
- int a = entry.Value.IndexOf("{{pokrewne}}") + "{{pokrewne}}".Length;
- int b = entry.Value.IndexOf("{{frazeologia}}", a);
- string relatedTerms = entry.Value.Substring(a, b - a).Trim();
- string verb = entry.Key.Split(' ')[0];
- if (relatedTerms.Contains("("))
- {
- exceptionList.Add(entry.Key);
- continue;
- }
- if (!relatedTerms.Contains("{{czas}}"))
- {
- workList.Add(entry.Key);
- continue;
- }
- a = relatedTerms.IndexOf("{{czas}}");
- b = relatedTerms.IndexOf("\n", a);
- string verbs = relatedTerms.Substring(a, (b != -1) ? b - a : relatedTerms.Length - a);
- if (!verbs.Contains("[[" + verb + "]]"))
- {
- workList.Add(entry.Key);
- continue;
- }
- }
- Console.WriteLine("Tamaño de la lista: " + workList.Count);
- //File.WriteAllLines("worklist.txt", workList);
- IDictionary<string, DateTime> timestamps = wb.GetTimestamps(workList);
- ICollection<string> errors = new List<string>();
- foreach (var entry in workList)
- {
- int section = wb.GetSectionId(entry, LanguageCodes.EN);
- string text = wb.GetSectionText(contentMap[entry], LanguageCodes.EN);
- string verb = entry.Split(' ')[0];
- int a = text.IndexOf("{{pokrewne}}") + "{{pokrewne}}".Length;
- int b = text.IndexOf("{{frazeologia}}", a);
- string relatedTerms = text.Substring(a, b - a).Trim();
- if (relatedTerms.Contains("{{czas}}"))
- {
- a = text.IndexOf("{{czas}}");
- b = text.IndexOf("\n", a);
- text = text.Substring(0, b) + ", [[" + verb + "]]" + text.Substring(b, text.Length - b);
- }
- else
- {
- text = text.Substring(0, b) + ": {{czas}} [[" + verb + "]]\n" + text.Substring(b, text.Length - b);
- }
- string summary = "dodanie czasownika bazowego do pokrewnych";
- DateTime baseTime = timestamps[entry];
- try
- {
- wb.Edit(entry, text, summary, false, true, section, baseTime);
- }
- catch (NotSupportedException e)
- {
- Console.WriteLine(e.Message + " - " + entry);
- errors.Add(entry);
- }
- }
- if (errors.Count != 0)
- {
- Console.WriteLine("Errores ({0}) en: {1}", errors.Count, errors.ToString());
- }
- wb.Logout();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement