Advertisement
abcd124646

Untitled

Sep 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Fizzler.Systems.HtmlAgilityPack;
  8. using HtmlAgilityPack;
  9.  
  10. namespace GetEm
  11. {
  12.     class Data
  13.     {
  14.         public string Name;
  15.         public int Count;
  16.  
  17.         public Data(string name, int count)
  18.         {
  19.             Name = name;
  20.             Count = count;
  21.         }
  22.  
  23.         public Data()
  24.         {
  25.  
  26.         }
  27.  
  28.         public override string ToString()
  29.         {
  30.             return $"{Name}  {Count}";
  31.         }
  32.     }
  33.  
  34.     class Program
  35.     {
  36.  
  37.      
  38.         static void Main(string[] args)
  39.         {
  40.             List<Data> inputData = new List<Data>();
  41.             HtmlDocument doc = new HtmlDocument();
  42.             doc.Load("Shinkai Project - general.html");
  43.  
  44.             var document = doc.DocumentNode;
  45.  
  46.             var chatlog=document.QuerySelectorAll(".chatlog__reaction");
  47.             foreach (var htmlNode in chatlog)
  48.             {
  49.                 try
  50.                 {
  51.                     string name=htmlNode.QuerySelector("img").GetAttributeValue("title","");
  52.                     int count = Convert.ToInt32(htmlNode.QuerySelector(".chatlog__reaction-count").InnerText);
  53.                     inputData.Add(new Data(name, count));
  54.                 }
  55.                 catch (Exception e)
  56.                 {
  57.                     //Console.WriteLine(e);
  58.                 }
  59.             }
  60.  
  61.             var uniqueKeys = inputData.Select(n => n.Name).Distinct().ToList();
  62.  
  63.             List<Data> outputData = new List<Data>();
  64.  
  65.             foreach (var uniqueKey in uniqueKeys)
  66.             {
  67.                 Data o = new Data();
  68.                 o.Name = uniqueKey;
  69.                 o.Count = inputData.Where(n => n.Name == uniqueKey).Sum(n => n.Count);
  70.                 outputData.Add(o);
  71.             }
  72.  
  73.             File.WriteAllLines("output.txt",outputData.OrderByDescending(n => n.Count).Select(n=>n.ToString()).ToArray());
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement