Exemple #1
0
 public static void Main(string[] args)
 {
     if (args.Length > 0)
     {
         if (string.Equals(args[0], "--map", StringComparison.OrdinalIgnoreCase))
         {
             Logger.Start();
             Logger.WriteLine("Starting program...");
             if (!Mapping.FileExists())
             {
                 Mapping.CreateFile();
             }
             Mapping.UpdateMap();
             Mapping.UpdateFile();
             Logger.WriteLine("Program finished.");
             Logger.Stop();
         }
         else
         {
             Console.WriteLine($"Unknown flag(s) found \"{string.Join (' ', args)}\". Use no flags to generate the Kattis table or use \"--map\" to update KattisMapping.txt.");
         }
     }
     else
     {
         ValidExtensions.LoadExtensions();
         Logger.Start();
         Logger.WriteLine("Starting program...");
         if (!Mapping.FileExists())
         {
             Mapping.CreateFile();
         }
         Mapping.AssignMappings();
         Config    config    = new Config();
         Generator generator = new Generator(config);
         generator.ProcessConfig();
         using (StreamWriter file = new StreamWriter("README.md", false, UnicodeEncoding.Default, 1 << 16)) {
             Logger.WriteLine("Writing to README.md");
             file.WriteLine("# Kattis Solutions");
             file.WriteLine("Some solutions may be outdated and could be revised.\n");
             string table = generator.GetTableString();
             file.WriteLine(table);
         }
         Logger.WriteLine("Program finished.");
         Logger.Stop();
     }
 }
Exemple #2
0
 private void TryAdd(string url, string id, string ext)
 {
     if (!ValidExtensions.Contains(ext))
     {
         Logger.WriteLine($"Unknown extension found: {ext}");
         return;
     }
     if (table.ContainsKey(id))
     {
         KattisProblem problem = table[id];
         string        lang    = ValidExtensions.Get(ext);
         if (!problem.Contains(lang))
         {
             Logger.WriteLine($"Added {lang} to problem {id}");
             problem.Add(lang, url);
         }
         else
         {
             Logger.WriteLine($"{lang} already found in problem {id}");
         }
     }
     else
     {
         string name = string.Empty;
         if (Mapping.ContainsKey(id))
         {
             name = Mapping.Get(id);
         }
         else
         {
             HtmlDocument doc  = web.Load($"https://open.kattis.com/problems/{id}");
             HtmlNode     node = doc.DocumentNode.SelectSingleNode("//head/title");
             if (node != null)
             {
                 Match match = Regex.Match(node.InnerHtml, @"(.+) &ndash; Kattis, Kattis");
                 name = WebUtility.HtmlDecode(match.Groups[1].ToString());
             }
             else
             {
                 Logger.WriteLine($"Could not find title: https://open.kattis.com/problems/{id}");
             }
         }
         if (!string.IsNullOrEmpty(name) && !name.Equals("404: Not Found"))
         {
             table.Add(id, new KattisProblem(name, id));
             KattisProblem problem = table[id];
             string        lang    = ValidExtensions.Get(ext);
             if (!problem.Contains(lang))
             {
                 Logger.WriteLine($"Added {lang} to problem {id}");
                 problem.Add(lang, url);
             }
             else
             {
                 Logger.WriteLine($"{lang} already found in problem {id}");
             }
         }
         else
         {
             Logger.WriteLine($"Invalid name found with: {url} {id} {ext}");
         }
     }
 }