static void UpdateListAndNotify(List <string> newestList) { if (newestList == null || newestList.Count == 0) { return; } if (CurrentList == null || CurrentList.Count == 0) { CurrentList = newestList; return; } int newCount = 0; foreach (string item in newestList) { if (!CurrentList.Exists(s => s == item)) { bool isSendSuccess = false; int retry = 10; for (int i = 0; i < retry && isSendSuccess == false; i++) { // Notify new item isSendSuccess = wechatNotifier.SendNotifier(item, $"详情见官网公告({USTCListAddress})"); newCount++; Console.WriteLine($"[New] {DateTime.Now} | {item} (Notify Status: {isSendSuccess})"); if (!isSendSuccess) { System.Threading.Thread.Sleep(500); } } } } if (newCount > 0) { // Update current list CurrentList = newestList; } else { Console.WriteLine($"{DateTime.Now} | No new list item"); } }
static async Task Main(string[] args) { // Register for GB2312 encoding Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Configurate notifier if (!File.Exists(SCKEYFileName) || File.ReadAllText(SCKEYFileName).Trim().Equals("")) { File.Create(SCKEYFileName); Console.WriteLine(@"Please configurate your SCKEY in file """ + SCKEYFileName + @""", you can generate your unique SCKEY from http://sc.ftqq.com/."); return; } string SCKEY = File.ReadAllText(SCKEYFileName).Trim(); wechatNotifier = new WechatNotifier(SCKEY); Console.WriteLine($"{DateTime.Now} | SCKEY = {SCKEY}"); // Start int errTime = 0; bool sentErr = false; while (true) { List <string> USTCList = await GetUSTCList(); if (USTCList.Count == 0) { errTime++; // Only send once every error period. if (errTime >= 10 && !sentErr) { sentErr = wechatNotifier.SendNotifier("[异常] USTCLIST 获取失败", "USTC List 已连续 10 次获取失败,请检查调试!"); } Console.WriteLine($"[Err] {DateTime.Now} Failed to get list."); continue; } // Reset error send status. errTime = 0; sentErr = false; UpdateListAndNotify(USTCList); System.Threading.Thread.Sleep(15000); } }
private void Timer_Tick(object sender, EventArgs e) { // Update stock list current price information Share share = null; foreach (ListViewItem lvi in listView_StockList.Items) { share = GetShareByCode(lvi.Text); // if (!IsTradingTime(share.shareData.dataTime)) continue; lvi.SubItems[subitemIndex_CurrentPrice].Text = share.shareData.currentPrice; if (lvi.SubItems[subitemIndex_CurrentPrice].Text != "") { int warningType = -1; float currentPrice = float.Parse(lvi.SubItems[subitemIndex_CurrentPrice].Text); float upPrice = lvi.SubItems[subitemIndex_UpPrice].Text == "" ? 0 : float.Parse(lvi.SubItems[subitemIndex_UpPrice].Text); float downPrice = lvi.SubItems[subitemIndex_DownPrice].Text == "" ? 0 : float.Parse(lvi.SubItems[subitemIndex_DownPrice].Text); if (currentPrice == 0) { continue; } // Warning Type jugement if (upPrice != 0 && upPrice <= currentPrice) { warningType = 0; } if (downPrice != 0 && downPrice >= currentPrice) { warningType = 1; } if (warningType != -1) { // Highlight warning item in listview lvi.ForeColor = warningType == 0 ? Color.Red : Color.Green; if (!WarningMessageBox.isShareBind(share)) { // Wechat notify int retry = 3; string title = "[" + share.shareInfo.shareUrlCode + "] " + share.shareData.shareName + " 触发" + (warningType == 0 ? "上" : "下") + "破价格 " + lvi.SubItems[subitemIndex_DownPrice].Text; string content = title + ", 现价 " + share.shareData.currentPrice; WechatNotifier wechatNotifier = new WechatNotifier(Notify_SCKEY); if (wechatNotify.Checked) { int i = 1; for ( ; i <= retry; i++) { if (wechatNotifier.SendNotifier(title, content)) { break; } } if (i > retry) { Console.WriteLine("微信提醒失败,请检查 SCKEY 是否填写正确"); } } // Create Warning Messagebox WarningMessageBox msg = new WarningMessageBox(share, warningType, lvi.SubItems[subitemIndex_DownPrice].Text, this); msg.Show(); } // Play sound warningdPlayer.Play(); } else { lvi.ForeColor = Color.Black; } } } // Update Infomation Panal if (Get2DisplayShareInfomationByCode(textBox_StockCode.Text)) { this.Text = Formtitle + " (Stock data has update: " + System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + " )"; } else { this.Text = Formtitle + " (Request Error!)"; pictureBox_StockImage.Image = null; } if (--GCTimeFlow < 0) { GC.Collect(); GCTimeFlow = GCTime; } // Update notifyIcon text int bindCount = WarningMessageBox.getBindCount(); if (bindCount == 0) { notifyIcon1.Text = "当前无预警触发"; } else { notifyIcon1.Text = "当前有" + String.Concat(bindCount) + "条预警被触发!"; } }