Exemplo n.º 1
0
        public WeekTimetable Clone()
        {
            var nw = new WeekTimetable(weekStartDay);

            foreach (var d in days)
            {
                nw.days.Add(d.Clone());
            }

            return(nw);
        }
Exemplo n.º 2
0
        public static WeekTimetable getTimetable(string timetable_url, DateTime week_start)
        {
            var timetable = new WeekTimetable(week_start);

            var formatted_date = week_start.ToString("yyyy-MM-dd");

            UnityEngine.Debug.LogWarning("Getting html from " + "http://timetable.spbu.ru" + timetable_url + "/" + formatted_date);
            var html = getHtmlFromUrl("http://timetable.spbu.ru/" + timetable_url + "/" + formatted_date);


            var dayNodes = html.DocumentNode.SelectNodes("*//div[contains(@class, 'panel-default')]");

            if (dayNodes != null)
            {
                foreach (var d in dayNodes)
                {
                    var day_of_week_str = d.SelectSingleNode("*//*[@class='panel-title']/text()").InnerText.Trim();
                    var day_of_week     = parseDayOfWeek(day_of_week_str);

                    //Console.WriteLine (day_of_week+" - "+week_start.AddDays((int)day_of_week-1).Date.DayOfWeek);

                    var dayTimetable = new DayTimetable(week_start.AddDays((int)day_of_week - 1).Date);

                    // parse day pairs

                    var pairNodes = d.SelectNodes("ul/li");
                    if (pairNodes != null)
                    {
                        foreach (var pairNode in pairNodes)
                        {
                            var time     = pairNode.SelectSingleNode("div[contains(@class, 'studyevent-datetime')]").InnerText.Trim();
                            var name     = pairNode.SelectSingleNode("div[contains(@class, 'studyevent-subject')]").InnerText.Trim();
                            var location = getAllText(pairNode.SelectSingleNode("div[contains(@class, 'locations')]")).Trim();
                            var lecturer = getAllText(pairNode.SelectSingleNode("div[contains(@class, 'educators')]")).Trim();
                            //Console.WriteLine (time);
                            //Console.WriteLine (name);
                            //Console.WriteLine (location);
                            //Console.WriteLine (lecturer);
                            //var old_hash = GetOLDPairMD5 (dayTimetable.day, name, time, location, lecturer, day_of_week);
                            var hash = GetPairMD5(dayTimetable.day.DayOfWeek, time, name, location, lecturer, timetable.weekType);

                            var pair = new Pair(dayTimetable.day, name, time, location, lecturer, false, false, "");
                            pair.hash         = TimetableParser.GetPairMD5(pair.day.DayOfWeek, pair.time, pair.name, pair.location, pair.lecturer, timetable.weekType);
                            pair.initial_hash = TimetableParser.GetOLDPairMD5(pair.time, pair.name, pair.location, pair.lecturer, timetable.weekType);

                            UnityEngine.Debug.LogWarning("NEW TIME: " + time);

                            dayTimetable.pairs.Add(pair);
                        }
                    }
                    else
                    {
                        //		Console.WriteLine ("Pairs Not found");
                    }

                    timetable.days.Add(dayTimetable);
                }
            }
            else
            {
                //Console.WriteLine ("Days Not found");
            }



            return(timetable);
        }