Beispiel #1
0
 public void ModifySchedule(string CourseName)
 {
     PrintSchedule(CourseName);
     Prompt._Prompt("輸入格式:加入or刪除(I or D) 星期幾(1-7) 第幾節課(1-10)");
     Prompt._Prompt("註:第5節為中午12:00");
     Prompt._Prompt("註:格式錯誤將自動退出設定");
     while (true)
     {
         string input = Prompt.Input("請輸入:");
         Match  mh    = Regex.Match(input, "([ID]) ([1-7]) ([0-9]{1,2})");
         if (mh.Success)
         {
             int    week       = int.Parse(mh.Groups[2].Value);
             int    courseTime = int.Parse(mh.Groups[3].Value);
             string mode       = mh.Groups[1].Value;
             if (mode == "I")
             {
                 schedule[week - 1, courseTime - 1] = CourseName;
                 Prompt.Success($"{CourseName}上課時間 => 星期{_week[week - 1]} 第{courseTime}節({courseTime + 7}:00~{courseTime + 8}:00)");
             }
             else if (mode == "D")
             {
                 schedule[week - 1, courseTime - 1] = "";
                 Prompt.Success($"刪除 {CourseName}的星期{_week[week - 1]} 第{courseTime}節({courseTime + 7}:00~{courseTime + 8}:00)");
             }
         }
         else
         {
             Prompt.Error("格式錯誤 退出設定!");
             break;
         }
     }
 }
Beispiel #2
0
        public void Start(List <Course> courses)
        {
            t = new Timer((e) =>
            {
                DateTime dt = DateTime.Now;
                //default 17
                if (dt.Hour >= 8 && dt.Hour <= 17)
                {
                    //default -8
                    if (schedule[dt.DayOfWeek.GetHashCode() - 1, dt.Hour - 8] != "")
                    {
                        string targetCourse   = schedule[dt.DayOfWeek.GetHashCode() - 1, dt.Hour - 8];
                        string courseSignHtml = Request($"student5/irs/rollcall/{courses.Find(x=>x.course_name==targetCourse).course_id}");
                        System.Threading.Thread.Sleep(250);
                        try
                        {
                            //檢查是否簽到過
                            if (Regex.IsMatch(courseSignHtml, "<div class=\"i-r-f-b-disabled-button\">已簽到</div>"))
                            {
                                return;
                            }
                            string rollcall_id = getVariable(courseSignHtml, "rollcall_id", isNum: false);

                            Prompt.DateTimeOutput($"發現有進行中的點名({targetCourse})");
                            Prompt.DateTimeOutput("開始簽到");
                            Thread.Sleep(250);
                            string lat = string.Empty;
                            string lng = string.Empty;
                            if (Location.ContainsKey(targetCourse))
                            {
                                string[] split = Location[targetCourse].Split(",");
                                lng            = split[0]; //經度
                                lat            = split[1]; //緯度
                            }

                            Sign sign = SignUp(rollcall_id, lat: lat, lng: lng);
                            if (sign.msg == "OK")
                            {
                                Console.ForegroundColor = Prompt.successColor;
                                Prompt.DateTimeOutput("簽到結果:成功");
                            }
                            else
                            {
                                Console.ForegroundColor = Prompt.errorColor;
                                Prompt.DateTimeOutput("簽到結果:失敗");
                            }
                            Console.ForegroundColor = Prompt.queryColor;
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message != "Can't Find rollcall_id value")
                            {
                                Prompt.Error(ex.ToString());
                            }
                        }
                    }
                }
            }, null, 0, DelayTime * 1000);
        }
Beispiel #3
0
        private void Login()
        {
            string url = "https://irs.zuvio.com.tw/irs/submitLogin";
            NameValueCollection param = HttpUtility.ParseQueryString(string.Empty);

            param.Add("email", account);
            param.Add("password", password);
            param.Add("current_language", "zh-TW");
            byte[] b = Encoding.ASCII.GetBytes(param.ToString());

            HttpWebRequest web = WebRequest.Create(url) as HttpWebRequest;


            web.Method      = "POST";
            web.ContentType = "application/x-www-form-urlencoded";
            //不設置cookie container 會無法登入
            web.CookieContainer = new CookieContainer();


            web.ContentLength = b.Length;
            using (Stream stream = web.GetRequestStream())
            {
                stream.Write(b, 0, b.Length);
            }


            using (HttpWebResponse response = web.GetResponse() as HttpWebResponse)
                using (Stream stream = response.GetResponseStream())
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        try
                        {
                            string html = sr.ReadToEnd();
                            AccessToken = getVariable(html, "accessToken", isNum: false);
                            UserID      = getVariable(html, "user_id");
                            Session     = response.Cookies[0].Value;
                        }catch (Exception ex)
                        {
                            Prompt.Error("帳號or密碼錯誤 請重新輸入");
                            new Zuvio();
                        }
                    }
        }
Beispiel #4
0
 public void ModifyLocation(string CourseName)
 {
     while (true)
     {
         Prompt._Prompt("輸入格式:經度,緯度");
         string input = Prompt.Input("請輸入:");
         Match  mh    = Regex.Match(input, "[0-9]+.[0-9]*,[0-9]+.[0-9]*");
         if (mh.Success)
         {
             Location[CourseName] = mh.Groups[0].Value;
             Prompt.Success($"{CourseName}定位地點 => {input}");
             break;
         }
         else
         {
             Prompt.Error(Prompt.FormatError);
         }
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.Title          = "Zuvio 自動點名系統 Ver1.3 by.Wind";
            Zuvio         zuvio   = new Zuvio();
            List <Course> courses = zuvio.GetCourses();
            string        select  = string.Empty;

            while (true)
            {
                Prompt._Prompt("輸入格式:編號");
                Prompt._Prompt("0.開啟自動簽到");
                Prompt._Prompt($"1.設定檢查時間(Current DelayTime:{zuvio.DelayTime}s)");
                Prompt._Prompt("↓↓以下為設定課程時間↓↓");
                Prompt._Prompt("輸入格式:編號 設定時間orGPS定位地點(T or G)");
                int num = 1;
                courses.ForEach(x =>
                {
                    num++;
                    Prompt._Prompt($"{num}.{x.course_name}");
                });

                select = Prompt.Input("請輸入:");
                Console.ForegroundColor = ConsoleColor.White;
                Prompt.SplitLine();
                if (select == "0")
                {
                    break;
                }
                else if (select == "1")
                {
                    while (!int.TryParse(Prompt.Input("請輸入檢查時間(單位:秒):"), out zuvio.DelayTime))
                    {
                        Prompt.Error(Prompt.FormatError);
                    }
                }
                else
                {
                    Match mh = Regex.Match(select, "([0-9]) ([TG])", RegexOptions.IgnoreCase);
                    if (mh.Success)
                    {
                        string mode       = mh.Groups[2].Value.ToUpper();
                        string courseName = courses[int.Parse(mh.Groups[1].Value) - 2].course_name;
                        if (mode == "T")
                        {
                            zuvio.ModifySchedule(courseName);
                        }
                        else if (mode == "G")
                        {
                            zuvio.ModifyLocation(courseName);
                        }
                    }
                    else
                    {
                        Prompt.Error(Prompt.FormatError);
                    }
                }
                Console.ForegroundColor = ConsoleColor.White;
                Prompt.SplitLine();
            }

            File.WriteAllText("Setting.json", JsonConvert.SerializeObject(zuvio));
            Prompt.DateTimeOutput("Zuvio 自動點名啟動");
            Prompt.DateTimeOutput("按下任意鍵結束程式");
            zuvio.Start(courses);
            Console.Read();
            zuvio.Stop();
        }