fork download
  1. using Sgml;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Xml.Linq;
  10.  
  11. // SgmlReaderに依存しています (https://w...content-available-to-author-only...t.org/packages/SgmlReader/)
  12. // グラフ作成にはイーグラフを使用しています (https://e...content-available-to-author-only...h.com/)
  13. // AILEくん大好き
  14.  
  15. namespace ConsoleApplication1
  16. {
  17. class Program
  18. {
  19. static XDocument ParseHtml(Uri url)
  20. {
  21. using (var stream = new WebClient().OpenRead(url))
  22. using (var reader = new StreamReader(stream, Encoding.GetEncoding("EUC-JP")))
  23. using (var sgmlReader = new SgmlReader { DocType = "HTML", CaseFolding = CaseFolding.ToLower, IgnoreDtd = true, InputStream = reader })
  24. {
  25. return XDocument.Load(sgmlReader);
  26. }
  27. }
  28.  
  29. static IEnumerable<Uri> ParseThread(Uri url)
  30. {
  31. var baseUrl = new Uri("http://j...content-available-to-author-only...a.net");
  32. var pattern = "^(/bbs/read.cgi/|/internet/20196/storage/)";
  33. return ParseHtml(url)
  34. .Descendants("a")
  35. .Select(x => x.Attribute("href").Value)
  36. .Where(x => Regex.IsMatch(x, pattern))
  37. .Select(x => new Uri(baseUrl, x));
  38. }
  39.  
  40. static DateTime ParseDateTime(Uri url)
  41. {
  42. var unixtime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  43. var time = url.Segments[1] == "bbs/"
  44. ? Regex.Match(url.Segments[5], @"^(\d+)/$")
  45. : Regex.Match(url.Segments[4], @"^(\d+).html$");
  46. var second = Int32.Parse(time.Groups[1].ToString());
  47. return unixtime.AddSeconds(second);
  48. }
  49.  
  50. static void Main(string[] args)
  51. {
  52. var subject = new Uri("http://j...content-available-to-author-only...a.net/bbs/subject.cgi/internet/20196/");
  53. var storage = new Uri("http://j...content-available-to-author-only...a.net/bbs/storage.cgi/internet/20196/");
  54.  
  55. var times = ParseThread(subject)
  56. .Concat(ParseThread(storage))
  57. .Select(ParseDateTime)
  58. .OrderBy(x => x)
  59. .GroupBy(x => x.Date)
  60. .Select(x => new { Date = x.Key, Count = x.Count() });
  61.  
  62. var path = @"../../../../time.tsv";
  63. using (var stream = File.Open(path, FileMode.Create))
  64. using (var writer = new StreamWriter(stream, Encoding.GetEncoding("shift-jis")))
  65. {
  66. writer.WriteLine("\tスレ数");
  67. foreach (var time in times)
  68. {
  69. if (time.Date.Year == 1970)
  70. writer.WriteLine("削除\t{0}", time.Count);
  71. else
  72. writer.WriteLine("{0}\t{1}", time.Date.ToString("M/d"), time.Count);
  73. }
  74. }
  75. }
  76. }
  77. }
  78.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `Sgml' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(9,18): error CS0234: The type or namespace name `Linq' does not exist in the namespace `System.Xml'. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty