{"id":2260,"date":"2018-04-10T21:04:09","date_gmt":"2018-04-10T19:04:09","guid":{"rendered":"http:\/\/soci.hu\/blog\/?p=2260"},"modified":"2018-04-10T21:04:09","modified_gmt":"2018-04-10T19:04:09","slug":"ha-valaki-jatszani-akar-a-valasztasi-adatokkal","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2018\/04\/10\/ha-valaki-jatszani-akar-a-valasztasi-adatokkal\/","title":{"rendered":"Ha valaki j\u00e1tszani akar a v\u00e1laszt\u00e1si adatokkal"},"content":{"rendered":"<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Text.RegularExpressions;\r\nusing System.Xml;\r\n\r\nnamespace ConsoleApp1\r\n{\r\n    class Program\r\n    {\r\n        static void Main()\r\n        {\r\n            new Program().Run();\r\n        }\r\n\r\n        private void Run()\r\n        {\r\n            Regex r = new Regex(@&quot;.+\\\\(\\w+)\\\\(\\w+).evkjkv.html&quot;, RegexOptions.Compiled | RegexOptions.IgnoreCase);\r\n\r\n            List&lt;string&gt; parties = new List&lt;string&gt;()\r\n            {\r\n                &quot;FIDESZ&quot;,\r\n                &quot;JOBBIK&quot;,\r\n                &quot;MSZP&quot;,\r\n                &quot;LMP&quot;,\r\n                &quot;EGY\u00dcTT&quot;,\r\n                &quot;DK&quot;,\r\n            };\r\n\r\n            foreach (var file in Directory.GetFiles(\r\n                @&quot;C:\\temp\\valasztas\\valasztas.hu\\dyn\\pv18\\szavossz\\hu\\&quot;, &quot;evkjkv.html&quot;, SearchOption.AllDirectories))\r\n            {\r\n                var d = FromHtml(file);\r\n\r\n                IEnumerable&lt;string&gt; cols = parties.Select(p =&gt;\r\n                {\r\n                    var part = GetVotes(d, file, p);\r\n                    return $&quot;{p},{part}&quot;;\r\n                });\r\n                string res = string.Join(&quot;,&quot;, cols);\r\n                var m = r.Match(file);\r\n                Console.WriteLine($&quot;{m.Groups&#x5B;1]},{m.Groups&#x5B;2]},{res}&quot;);\r\n            }\r\n        }\r\n\r\n        private static string GetVotes(XmlDocument d, string file, string party)\r\n        {\r\n            var n = d.SelectSingleNode($&quot;\/\/tr&#x5B;td&#x5B;starts-with(text(), '{party}')]]&quot;);\r\n            if (n == null)\r\n            {\r\n                return &quot;0&quot;;\r\n                \/\/Console.WriteLine($&quot;Skipping {file} because there is no data for {party}&quot;);\r\n            }\r\n\r\n            \/\/Console.WriteLine(n.InnerXml);\r\n            return n.SelectSingleNode(&quot;td&#x5B;4]&quot;).InnerText.Replace(&quot;&amp;amp;&quot;, &quot;&quot;).Replace(&quot;&amp;nbsp;&quot;, &quot;&quot;);\r\n        }\r\n\r\n        XmlDocument FromHtml(string path)\r\n        {\r\n            using (TextReader reader = File.OpenText(path))\r\n            {\r\n                XmlDocument doc;\r\n                using (var sgmlReader = new Sgml.SgmlReader\r\n                {\r\n                    DocType = &quot;HTML&quot;,\r\n                    WhitespaceHandling = WhitespaceHandling.All,\r\n                    CaseFolding = Sgml.CaseFolding.ToLower,\r\n                    InputStream = reader\r\n                })\r\n                {\r\n                    doc = new XmlDocument\r\n                    {\r\n                        PreserveWhitespace = true,\r\n                        XmlResolver = null\r\n                    };\r\n                    doc.Load(sgmlReader);\r\n                }\r\n\r\n                return doc;\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Xml; namespace ConsoleApp1 { class Program { static void Main() {&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2260","post","type-post","status-publish","format-standard","hentry","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2260"}],"version-history":[{"count":1,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2260\/revisions"}],"predecessor-version":[{"id":2261,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2260\/revisions\/2261"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}