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); }
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(); }