예제 #1
0
        }                                                             //links like this http://www.psp.cz/sqw/detail.sqw?id=252

        public pspProtocolPage(string URL) : this()
        {
            var webGet = Scraper.WebGetFactory();

            var html = webGet.Load(URL);

            URL = webGet.ResponseUri.ToString();
            if (html.DocumentNode.InnerText != "")
            {
                var mainContent = html.DocumentNode.SelectSingleNode("//div[@id = 'main-content']");
                var links       = mainContent.SelectNodes(".//a[@href]");
                var i           = 0;
                foreach (var link in links)
                {
                    var linkHref = link.GetAttributeValue("href", ""); //http://www.psp.cz/sqw/hlasy.sqw?G=56651
                    if (linkHref.Contains("detail.sqw"))               //http://www.psp.cz/sqw/detail.sqw?id=401
                    {
                        pspProfiles.Add(i, linkHref);
                    }
                    else
                    {
                        if (linkHref.Contains("hlasy.sqw"))
                        {
                            pspVotings.Add(i, linkHref);
                        }
                        else if (linkHref.Contains("historie.sqw"))         //http://www.psp.cz/sqw/historie.sqw?T=823&O=6
                        {
                            pspPrints.Add(i, linkHref);
                        }
                    }
                    i++;
                }
                if (pspPrints.Count == 0 && pspProfiles.Count == 0 && pspVotings.Count == 0)
                {
                    Console.WriteLine("This should not happen");
                }
            }
            else
            {
                throw new HtmlWebException("Requested URL " + URL + " seems to not yieald any response");
            }
        }
예제 #2
0
        public pspVoting(string URL)
        {
            var webLoader = Scraper.WebGetFactory();
            var document  = webLoader.Load(URL);

            try
            {
                URL = webLoader.ResponseUri.ToString();
                var mainContent = document.DocumentNode.SelectSingleNode("//div[@id = 'main-content']");
                var h1          = mainContent.SelectNodes(".//h1");
                var lis         = mainContent.SelectNodes(".//li");

                var headingText    = HttpUtility.HtmlDecode(h1.First().InnerText);
                var scrapedNumbers = ScraperStringHelper.GetNumbersFromString(headingText);

                Console.WriteLine(headingText);

                if (scrapedNumbers.Count == 6)
                {
                    var numbersAsInts = new List <int>();  //DateTime(int year, int month, int day, int hour, int minute, int second);
                    scrapedNumbers.ToList().ForEach(x => numbersAsInts.Add((int)x.Value));

                    meetingNumber = scrapedNumbers.ElementAt(0).Value;
                    votingNumber  = scrapedNumbers.ElementAt(1).Value;
                    subject       = headingText.Substring(headingText.LastIndexOf(":") + 3).Trim();

                    when = new DateTime(numbersAsInts.ElementAt(3), czechCalendarHelper.getMonthFromString(headingText), numbersAsInts.ElementAt(2), numbersAsInts.ElementAt(4), numbersAsInts.ElementAt(5), 0);

                    pspVotes = new List <individualVote>();
                    foreach (var LINode in lis)
                    {
                        if (isLINodeaVote(LINode))
                        {
                            var parliamentMemberLinkNode = LINode.LastChild;
                            var name = HttpUtility.HtmlDecode(parliamentMemberLinkNode.InnerText);
                            var link = Scraper.pspHostAppURL + parliamentMemberLinkNode.Attributes["href"].Value;

                            var vote = new individualVote()
                            {
                                member = new parliamentMember {
                                    name = name, pspUrl = link
                                }
                            };
                            switch (LINode.FirstChild.Attributes["class"].Value)
                            {
                            case "flag yes": vote.how = individualVotingTypes.Agrees;
                                break;

                            case "flag no": vote.how = individualVotingTypes.Disagrees;
                                break;

                            case "flag not-logged-in": vote.how = individualVotingTypes.NotPresent;
                                break;

                            case "flag refrained": vote.how = individualVotingTypes.Refrained;
                                break;

                            case "flag excused": vote.how = individualVotingTypes.NotPresentExcused;
                                break;
                            }
                            AddIndividualVote(vote);
                        }
                    }

                    //foreach (var vote in pspVotes)
                    //{
                    //    using (var session = pspScraper.Scraper.docDB.OpenSession())
                    //    {
                    //        var pspMember = session.Query<parliamentMember>().FirstOrDefault(x => x.pspUrl == vote.member.pspUrl);

                    //        session.Store(voting);

                    //        session.SaveChanges();
                    //    }
                    //}

                    Console.WriteLine("Added {0} votes", pspVotes.Count);
                }
                else
                {
                    throw new Exception {
                    };
                }
            }
            catch (Exception)
            {
                throw;
            }
        }