Advertisement
Guest User

plwikt 3.11.14

a guest
Nov 3rd, 2014
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using WikiEnv;
  9. using WikiEnv.Derived;
  10. using WikiEnv.Helpers;
  11.  
  12. namespace WikiTest
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             Console.OutputEncoding = Encoding.UTF8;
  19.             Wikibot wb = new Wikibot();
  20.             Login.Log(wb, true);
  21.             wb.Throttle = 3000;
  22.  
  23.             IDictionary<string, string> contentMap = wb.GetContentOfCategorymembers("Kategoria:phrasal verbs", LanguageCodes.EN);
  24.             ICollection<string> workList = new List<string>(500);
  25.             ICollection<string> exceptionList = new List<string>(50);
  26.  
  27.             foreach (var entry in contentMap)
  28.             {
  29.                 int a = entry.Value.IndexOf("{{pokrewne}}") + "{{pokrewne}}".Length;
  30.                 int b = entry.Value.IndexOf("{{frazeologia}}", a);
  31.  
  32.                 string relatedTerms = entry.Value.Substring(a, b - a).Trim();
  33.                 string verb = entry.Key.Split(' ')[0];
  34.  
  35.                 if (relatedTerms.Contains("("))
  36.                 {
  37.                     exceptionList.Add(entry.Key);
  38.                     continue;
  39.                 }
  40.  
  41.                 if (!relatedTerms.Contains("{{czas}}"))
  42.                 {
  43.                     workList.Add(entry.Key);
  44.                     continue;
  45.                 }
  46.  
  47.                 a = relatedTerms.IndexOf("{{czas}}");
  48.                 b = relatedTerms.IndexOf("\n", a);
  49.  
  50.                 string verbs = relatedTerms.Substring(a, (b != -1) ? b - a : relatedTerms.Length - a);
  51.  
  52.                 if (!verbs.Contains("[[" + verb + "]]"))
  53.                 {
  54.                     workList.Add(entry.Key);
  55.                     continue;
  56.                 }
  57.             }
  58.  
  59.             Console.WriteLine("Tamaño de la lista: " + workList.Count);
  60.             //File.WriteAllLines("worklist.txt", workList);
  61.  
  62.             IDictionary<string, DateTime> timestamps = wb.GetTimestamps(workList);
  63.             ICollection<string> errors = new List<string>();
  64.  
  65.             foreach (var entry in workList)
  66.             {
  67.                 int section = wb.GetSectionId(entry, LanguageCodes.EN);
  68.  
  69.                 string text = wb.GetSectionText(contentMap[entry], LanguageCodes.EN);
  70.                 string verb = entry.Split(' ')[0];
  71.  
  72.                 int a = text.IndexOf("{{pokrewne}}") + "{{pokrewne}}".Length;
  73.                 int b = text.IndexOf("{{frazeologia}}", a);
  74.  
  75.                 string relatedTerms = text.Substring(a, b - a).Trim();
  76.  
  77.                 if (relatedTerms.Contains("{{czas}}"))
  78.                 {
  79.                     a = text.IndexOf("{{czas}}");
  80.                     b = text.IndexOf("\n", a);
  81.  
  82.                     text = text.Substring(0, b) + ", [[" + verb + "]]" + text.Substring(b, text.Length - b);
  83.                 }
  84.                 else
  85.                 {
  86.                     text = text.Substring(0, b) + ": {{czas}} [[" + verb + "]]\n" + text.Substring(b, text.Length - b);
  87.                 }
  88.  
  89.                 string summary = "dodanie czasownika bazowego do pokrewnych";
  90.                 DateTime baseTime = timestamps[entry];
  91.  
  92.                 try
  93.                 {
  94.                     wb.Edit(entry, text, summary, false, true, section, baseTime);
  95.                 }
  96.                 catch (NotSupportedException e)
  97.                 {
  98.                     Console.WriteLine(e.Message + " - " + entry);
  99.                     errors.Add(entry);
  100.                 }
  101.             }
  102.  
  103.             if (errors.Count != 0)
  104.             {
  105.                 Console.WriteLine("Errores ({0}) en: {1}", errors.Count, errors.ToString());
  106.             }
  107.  
  108.             wb.Logout();
  109.             Console.ReadKey();
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement