Ejemplo n.º 1
0
        public static List <TimeTableSemester> ListingSemesters(this EverytimeSession session)
        {
            var request = session.CreatePostRequest("https://api.everytime.kr/find/timetable/subject/semester/list");
            var res     = (HttpWebResponse)request.GetResponse();
            var gz      = new BinaryReader(new GZipStream(res.GetResponseStream(), CompressionMode.Decompress)).ReadBytes(65535);
            var xml     = Encoding.UTF8.GetString(gz);

            res.Close();

            var document = new HtmlDocument();

            document.LoadHtml(xml);
            var root_node = document.DocumentNode;

            var result = new List <TimeTableSemester>();

            foreach (var semester in root_node.SelectNodes("//semester"))
            {
                result.Add(new TimeTableSemester
                {
                    Year               = semester.GetAttributeValue("year", ""),
                    Semester           = semester.GetAttributeValue("semester", ""),
                    StartDate          = semester.GetAttributeValue("start_date", ""),
                    EndDate            = semester.GetAttributeValue("end_date", ""),
                    IsFormal           = semester.GetAttributeValue("is_formal", ""),
                    IsSupported        = semester.GetAttributeValue("is_supported", ""),
                    HasSyllabus        = semester.GetAttributeValue("has_syllabus", ""),
                    HasSubjectDatabase = semester.GetAttributeValue("has_subject_database", ""),
                    UpdatedAt          = semester.GetAttributeValue("updated_at", ""),
                });
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static List <string> GetHacksuFromTableInfo(this EverytimeSession session, TimeTableTable table)
        {
            var request = session.CreatePostRequest("https://api.everytime.kr/find/timetable/table");
            var rs      = new StreamWriter(request.GetRequestStream());

            rs.Write($"id={table.Id}");
            rs.Close();
            var res = (HttpWebResponse)request.GetResponse();
            var gz  = new BinaryReader(new GZipStream(res.GetResponseStream(), CompressionMode.Decompress)).ReadBytes(65535 * 128);
            var xml = Encoding.UTF8.GetString(gz);

            res.Close();

            var document = new HtmlDocument();

            document.LoadHtml(xml);
            var root_node = document.DocumentNode;

            var result = new List <string>();

            foreach (var subject in root_node.SelectNodes("//internal"))
            {
                result.Add(subject.GetAttributeValue("value", ""));
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static EverytimeSession Create(string id, string pwd)
        {
            var request = (HttpWebRequest)WebRequest.Create("https://everytime.kr/user/login");

            request.Method = "POST";
            request.Headers.Add("Origin", "https://everytime.kr/");
            request.Referer     = "https://everytime.kr/";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Accept      = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            request.UserAgent   = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0";
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            request.Headers.Add(HttpRequestHeader.AcceptLanguage, "ko,en-US;q=0.7,en;q=0.3");
            request.Host              = "everytime.kr";
            request.CookieContainer   = new CookieContainer();
            request.AllowAutoRedirect = false;

            var request_stream = new StreamWriter(request.GetRequestStream());

            request_stream.Write($"userid={id}&password={pwd}&redirect=%2F");
            request_stream.Close();

            //
            //  Create Session
            //

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                var cookies = response.Cookies;

                // Fake response
                var res = new StreamReader(response.GetResponseStream()).ReadToEnd();

                if (cookies.Count == 0 || cookies[0].Name != "etsid")
                {
                    return(null);
                }

                var ms = new EverytimeSession {
                    Cookies = cookies
                };

                return(ms);
            }
        }
Ejemplo n.º 4
0
        public static List <TimeTableTable> GetTableListFromSemester(this EverytimeSession session, TimeTableSemester semester)
        {
            var request = session.CreatePostRequest("https://api.everytime.kr/find/timetable/table/list/semester");
            var rs      = new StreamWriter(request.GetRequestStream());

            rs.Write($"year={semester.Year}&semester={Uri.EscapeDataString(semester.Semester)}");
            rs.Close();
            var res = (HttpWebResponse)request.GetResponse();
            var gz  = new BinaryReader(new GZipStream(res.GetResponseStream(), CompressionMode.Decompress)).ReadBytes(65535);
            var xml = Encoding.UTF8.GetString(gz);

            res.Close();

            var document = new HtmlDocument();

            document.LoadHtml(xml);
            var root_node = document.DocumentNode;

            var result = new List <TimeTableTable>();

            if (root_node.SelectNodes("//table") != null)
            {
                foreach (var table in root_node.SelectNodes("//table"))
                {
                    result.Add(new TimeTableTable
                    {
                        Id        = table.GetAttributeValue("id", ""),
                        Name      = table.GetAttributeValue("name", ""),
                        Priv      = table.GetAttributeValue("priv", ""),
                        IsPrimary = table.GetAttributeValue("is_primary", ""),
                        CreatedAt = table.GetAttributeValue("created_at", ""),
                        UpdatedAt = table.GetAttributeValue("updated_at", ""),
                    });
                }
            }

            return(result);
        }