Пример #1
0
        public ArticleMark(string link, List <ArticleCriteria> articleList)
        {
            this.FacultyName = ArticleCriteria.GetFaculty(link);

            this.ArticleNumber = (articleList.Count);

            this.LastArticleDate = articleList.Max(a => a.Date);
        }
Пример #2
0
        public List <ArticleCriteria> CollectNewsInfo(string link, DateTime fromDate)
        {
            string faculty = GetFaculty(link);
            List <ArticleCriteria> articleList = new List <ArticleCriteria>();

            bool keepGoing  = true;
            int  pageNumber = 1;

            while (keepGoing)
            {
                string pageLink;
                if (pageNumber == 1)
                {
                    pageLink = link;
                }
                else
                {
                    pageLink = link + "/page/" + pageNumber.ToString();
                }

                HtmlWeb web = new HtmlWeb();
                var     res = web.Load(pageLink);

                if (res != null)
                {
                    // list of raw html fragments <article>(.*?)</article>
                    var articlesRaw = res.DocumentNode.SelectNodes("//article");
                    foreach (var articleRaw in articlesRaw)
                    {
                        var article = new ArticleCriteria(articleRaw, pageNumber, faculty);
                        try
                        {
                            if (article.Date >= fromDate)
                            {
                                articleList.Add(article);
                            }
                            else
                            {
                                //stop
                                keepGoing = false;
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            articleList.Add(article);
                        }
                    }
                    pageNumber += 1;
                }
                else
                {
                    keepGoing = false;
                }
            }
            return(articleList);
        }
Пример #3
0
        public void MainFunction()
        {
            // посилання на факультети
            string filenameRead = @"Data\faculty_links.txt";

            List <string> links = ExtractFacultyLinks(filenameRead);
            // посилання на списки кафедр, новин
            List <string> departmentLinks = ConcatanateLinks(links, "/about/departments");
            List <string> newsLinks       = ConcatanateLinks(links, "/news");

            string filenameWrite = ("report_department" + DateTime.Today.ToString("u") + ".txt").Replace(':', '.');

            using (StreamWriter f = new StreamWriter(filenameWrite, false))
            {
                f.WriteLine(string.Format("ФАКУЛЬТЕТ \t Кафедра \t Оцінка на {0}", DateTime.Today.ToString("dd.MM.yyyy")));
                for (int i = 0; i < departmentLinks.Count; i++)
                {
                    HtmlWeb web            = new HtmlWeb();
                    string  departmentLink = departmentLinks[i],
                            newsLink       = newsLinks[i];
                    var mainNews           = ExtractArticles(web.Load(newsLink).DocumentNode, "");
                    var htmlDoc            = web.Load(departmentLink);
                    var departments        = ExtractAllDepartments(htmlDoc.DocumentNode);
                    htmlDoc = web.Load(newsLink);
                    var    filters          = ExtractDepartmentsFromFilter(htmlDoc.DocumentNode);
                    var    departmentFilter = LinkDeparmentsToFilters(departments, filters);
                    double facultyMark      = new double();

                    string info_line = string.Format("{0}\n", ArticleCriteria.GetFaculty(departmentLink));
                    f.WriteLine(info_line);

                    foreach (var department in departmentFilter.Keys)
                    {
                        var departmentArticles = ExtractArticles(web.Load(department.
                                                                          Attributes["href"].Value).DocumentNode, "//body//div//div//section");
                        HtmlNodeCollection filterArticles;
                        try
                        {
                            filterArticles = ExtractArticles(web.Load(departmentFilter[department].
                                                                      Attributes["href"].Value).DocumentNode, "//body//div[@class='content news']");
                        }
                        catch (Exception e)
                        {
                            filterArticles = null;
                        }

                        double departmentMark = GetDepartmentMark(departmentArticles, filterArticles, mainNews);
                        dump_department_mark(f, department.InnerText, departmentMark);
                        facultyMark += departmentMark;
                    }

                    facultyMark /= departments.Count;
                    f.WriteLine(string.Format("ФАКУЛЬТЕТ \t Середня оцінка {0}", facultyMark));
                }
            }
        }
Пример #4
0
        //public void MainFunction()
        //{
        //    // посилання на персонал факультетів
        //    string filenameRead = @"Data\staff_links.txt";
        //    List<string> staffLinks = ExtractFacultyLinks(filenameRead);

        //    string filenameWrite = ("report_staff_" + DateTime.Now.ToString() + ".txt").Replace(':', '.');
        //    using (StreamWriter f = new StreamWriter(filenameWrite, false))
        //    {
        //        f.WriteLine(string.Format("Викладачі \t Оцінка на {0}", DateTime.Today.ToString("dd.MM.yyyy")));
        //        for (int i = 0; i < staffLinks.Count; i++)
        //        {
        //            HtmlWeb web = new HtmlWeb();
        //            string staffLink = staffLinks[i];
        //            var linksNodes = GetAllLecturerLinksNodes(web.Load(staffLink).DocumentNode);
        //            //отримання посилань на всіх працівників факультету
        //            var lecturerlinks = GetAllLecturerLinks(linksNodes);

        //            double facultyStaffMark = new double();
        //            string info_line = string.Format("Факультет {0}\n", ArticleCriteria.GetFaculty(staffLink));
        //            f.WriteLine(info_line);

        //            var lecturers = new List<Lecturer>();
        //            foreach (var lecturerLink in lecturerlinks)
        //            {
        //                var lecturer = new Lecturer();
        //                lecturer.SetLink(lecturerLink);
        //                try
        //                {
        //                    var lecturerPage = web.Load(lecturerLink).DocumentNode;
        //                    var infoRows = GetAllInfoRows(lecturerPage);
        //                    lecturer.SetName(lecturerPage);
        //                    lecturer.SetInfoFromRows(infoRows);
        //                }
        //                catch
        //                {
        //                }

        //                f.WriteLine(lecturer);
        //                //double departmentMark = GetDepartmentMark(departmentArticles, filterArticles, mainNews);
        //                //dump_department_mark(f, department.InnerText, departmentMark);
        //                //facultyMark += departmentMark;
        //            }

        //            //facultyMark /= departments.Count;
        //            //f.WriteLine(string.Format("ФАКУЛЬТЕТ \t Середня оцінка {0}", facultyMark));
        //        }
        //        f.WriteLine(string.Format("Час завершення {0}", DateTime.Now.ToString()));
        //    }
        //}

        public void MainFunction()
        {
            // посилання на персонал факультетів
            string        filenameRead = @"Data\staff_links.txt";
            List <string> staffLinks   = ExtractFacultyLinks(filenameRead);

            string filenameWrite = ("report_staff_" + DateTime.Now.ToString() + ".txt").Replace(':', '.');

            using (StreamWriter f = new StreamWriter(filenameWrite, false))
            {
                f.WriteLine(string.Format("Викладачі \t Оцінка на {0}", DateTime.Today.ToString("dd.MM.yyyy")));
            }
            for (int i = 0; i < staffLinks.Count; i++)
            {
                HtmlWeb web        = new HtmlWeb();
                string  staffLink  = staffLinks[i];
                var     linksNodes = GetAllLecturerLinksNodes(web.Load(staffLink).DocumentNode);
                //отримання посилань на всіх працівників факультету
                var lecturerlinks = GetAllLecturerLinks(linksNodes);

                double facultyStaffMark = new double();
                using (StreamWriter f = new StreamWriter(filenameWrite, true))
                {
                    string info_line = string.Format("Факультет {0}\n", ArticleCriteria.GetFaculty(staffLink));
                    f.WriteLine(info_line);
                }

                var lecturers = new List <Lecturer>();
                foreach (var lecturerLink in lecturerlinks)
                {
                    var lecturer = new Lecturer();
                    lecturer.SetLink(lecturerLink);
                    try
                    {
                        var lecturerPage = web.Load(lecturerLink).DocumentNode;
                        var infoRows     = GetAllInfoRows(lecturerPage);
                        lecturer.SetName(lecturerPage);
                        lecturer.SetInfoFromRows(infoRows);
                        var sections = GetAllSections(lecturerPage);
                        lecturer.SetInfoFromSections(sections);
                    }
                    catch
                    {
                    }
                    using (StreamWriter f = new StreamWriter(filenameWrite, true))
                    {
                        f.WriteLine(lecturer);
                    }

                    //double departmentMark = GetDepartmentMark(departmentArticles, filterArticles, mainNews);
                    //dump_department_mark(f, department.InnerText, departmentMark);
                    //facultyMark += departmentMark;
                }

                //facultyMark /= departments.Count;
                //f.WriteLine(string.Format("ФАКУЛЬТЕТ \t Середня оцінка {0}", facultyMark));
            }
            using (StreamWriter f = new StreamWriter(filenameWrite, true))
            {
                f.WriteLine(string.Format("Час завершення {0}", DateTime.Now.ToString()));
            }
        }
Пример #5
0
 public ArticleMark(DateTime LastArticleDate, int ArticleNumber, string FacultyName)
 {
     this.FacultyName     = ArticleCriteria.GetFaculty(FacultyName);
     this.ArticleNumber   = (ArticleNumber);
     this.LastArticleDate = (LastArticleDate);
 }