private void GetEQHashs(bool getFromWeb) { TestString = ""; GetJsonFile NetFile; NetFile = new GetJsonFile(); try { if (getFromWeb || EQJsonFile == "") { EQJsonFile = NetFile.GetJson("https://api.p2pquake.net/v2/jma/quake?limit=10&order=-1"); } List <EQRoot> JsonData = JsonConvert.DeserializeObject <List <EQRoot> >(EQJsonFile); //TestString = "Time : " + JsonData[0].created_at; DateTime created_at; DataConverter converter = new DataConverter(); created_at = converter.GetTime(JsonData[0].created_at); if (!converter.GetTimeError()) { EQLastUpdated = created_at; LoadEQData(JsonData[0], false); isFailEQInit = false; } } catch { isFailEQInit = true; } try { if (getFromWeb || EEWJsonFile == "") { EEWJsonFile = NetFile.GetJson("https://api.iedred7584.com/eew/json/"); } EEWRoot eew = JsonConvert.DeserializeObject <EEWRoot>(EEWJsonFile); EEWLatestUNIXTime = eew.AnnouncedTime.UnixTime; if (EEWLatestUNIXTime != 0) { isFailEEWInit = false; EEW_SerialCountTemp = eew.Serial; } } catch { isFailEEWInit = true; } try { if (getFromWeb || TsunamiJsonFile == "") { TsunamiJsonFile = NetFile.GetJson("https://api.p2pquake.net/v2/jma/tsunami?limit=10&order=-1"); } List <TsunamiRoot> tsunami = JsonConvert.DeserializeObject <List <TsunamiRoot> >(TsunamiJsonFile); DateTime created_at; DataConverter converter = new DataConverter(); created_at = converter.GetTime(tsunami[0].created_at); if (!converter.GetTimeError()) { TsunamiLastUpdated = created_at; LoadTsunamiData(tsunami[0], false); IsFailTsunamiInit = false; } } catch { IsFailTsunamiInit = true; } }
private void GetEEWJson() { try { GetJsonFile NetFile; NetFile = new GetJsonFile(); EEWJsonFile = NetFile.GetJson("https://api.iedred7584.com/eew/json/"); EEWRoot eew = JsonConvert.DeserializeObject <EEWRoot>(EEWJsonFile); Count_Request++; long UnixNowTime = eew.AnnouncedTime.UnixTime; if (eew.ParseStatus != "Success") { return; } if (UnixNowTime > EEWLatestUNIXTime || EEW_SerialCountTemp != eew.Serial) { if (UnixNowTime > EEWLatestUNIXTime + 300) { EEW_TweetMode = false; } EEW_SerialCountTemp = eew.Serial; DataConverter converter = new DataConverter(); if (eew.EventID != EEW_EventID) { EEW_EventID = eew.EventID; EEW_TweetMode = false; } bool cancel = false; EEWLatestUNIXTime = UnixNowTime; if (eew.Warn) { EEW_IndexText = "🔴🔴⚠緊急地震速報(警報)⚠🔴🔴"; } else { EEW_IndexText = "緊急地震速報(予報) "; } EEW_IndexText += "第 " + eew.Serial.ToString() + " 報"; string line = eew.OriginalText; string[] EEWData = line.Split(' '); if (eew.Type.Code == 9) { EEW_IndexText += "(最終報)"; } EEW_IndexText += "\n"; switch (int.Parse(eew.Status.Code)) { case 0: break; case 1: EEW_IndexText += "訓練\n"; return; case 10: EEW_IndexText += "キャンセル報\nこの緊急地震速報は取り消されました。\n"; cancel = true; break; case 11: EEW_IndexText += "訓練キャンセル\n"; return; case 20: EEW_IndexText += "参考もしくはテスト電文\n"; return; case 30: EEW_IndexText += "気象庁の配信テスト\n"; return; } if (!cancel) { if (eew.Hypocenter.isSea && eew.Hypocenter.Magnitude.Float >= 5.5) { EEW_IndexText += "🔴⚠津波発生の恐れがあります。\n"; } EEW_IndexText += eew.Hypocenter.Name + " 深さ:" + converter.DeepString(eew.Hypocenter.Location.Depth.Int) + " M" + eew.Hypocenter.Magnitude.Float.ToString("F1") + "\n" + "最大震度:" + eew.MaxIntensity.String + "\n" + "発生時刻:" + converter.GetTime(eew.OriginTime.String).ToString("M/dd H:mm:ss") + "\n"; if (eew.Warn) { EEW_IndexText += "以下の地域は強い揺れに警戒してください。\n"; for (int i = 0; i < eew.WarnForecast.LocalAreas.Count; i++) { EEW_IndexText += eew.WarnForecast.LocalAreas[i]; if (eew.WarnForecast.LocalAreas.Count - 1 != i) { EEW_IndexText += " "; } } EEW_IndexText += "\n"; } EEW_IndexText += "\n"; EEW_IndexText += converter.GetTime(eew.AnnouncedTime.String).ToString("M/dd H:mm:ss発表") + "\n"; } if (eew.Hypocenter.Magnitude.Float >= 4 || converter.ScaleValue(eew.MaxIntensity.To) >= 3 || EEW_TweetMode) { IsTweetedEEW = true; string tweetText = EEW_IndexText += "\n#MisakiEQ #地震 #緊急地震速報"; Twitter TwiCliant = new Twitter(); if (!EEW_TweetMode) { TwiCliant.Tweet(tweetText); } else { TwiCliant.Reply(EEW_LastTweetID, tweetText); } EEW_LastTweetID = TwiCliant.GetLatestTweetID(); EEW_TweetMode = true; } if (eew.Warn) { NotificationName = "⚠緊急地震速報(警報)"; } else { NotificationName = "緊急地震速報(予報)"; } NotificationName += " 第 " + eew.Serial.ToString() + " 報"; if (eew.Type.Code == 9) { NotificationName += "(最終報)"; } if (!cancel) { NotificationIndex = eew.Hypocenter.Name + " 深さ:" + converter.DeepString(eew.Hypocenter.Location.Depth.Int) + " M" + eew.Hypocenter.Magnitude.Float.ToString("F1") + "\n" + "最大震度:" + eew.MaxIntensity.String; DisplayingNotificationTime = 2147483647; if (eew.Hypocenter.isSea && eew.Hypocenter.Magnitude.Float > 5) { NotificationIndex += " 津波発生の可能性あり"; } } else { NotificationIndex = "キャンセル報\n緊急地震速報は取り消されました。"; IsTweetedEEW = false; } NotificationIcon = 2; IsDisplayNotification = true; } IsEEWStatusOK = true; } catch { IsEEWStatusOK = false; } finally { isEEWRun = false; } }
private void Update_Tick(object sender, EventArgs e) { //Test_Label.Text = TestString; EQ_Index.Text = EQ_IndexText; EEW_Index.Text = EEW_IndexText; Tsunami_Index.Text = Tsunami_Index_text; if (isFailEEWInit) { EEWInitOKLabel.Text = "初期化 : 失敗"; } else { if (IsEEWStatusOK) { EEWInitOKLabel.Text = "取得 : 成功"; } else { EEWInitOKLabel.Text = "取得 : 失敗"; } } if (isFailEQInit) { EQInitOKLabel.Text = "初期化 : 失敗"; } else { if (IsEQStatusOK) { EQInitOKLabel.Text = "取得 : 成功"; } else { EQInitOKLabel.Text = "取得 : 失敗"; } } if (IsFailTsunamiInit) { TsunamiInitOKLabel.Text = "初期化 : 失敗"; } else { if (IsTsunamiStatusOK) { TsunamiInitOKLabel.Text = "取得 : 成功"; } else { TsunamiInitOKLabel.Text = "取得 : 失敗"; } } RequestedCount.Text = "累計リクエスト数 : " + Count_Request.ToString(); if (IsDisplayNotification) { IsDisplayNotification = false; switch (NotificationIcon) { case 1: this.notification.BalloonTipIcon = ToolTipIcon.Info; break; case 2: this.notification.BalloonTipIcon = ToolTipIcon.Warning; break; case 3: this.notification.BalloonTipIcon = ToolTipIcon.Error; break; default: this.notification.BalloonTipIcon = ToolTipIcon.None; break; } this.notification.BalloonTipTitle = NotificationName; this.notification.BalloonTipText = NotificationIndex; this.notification.ShowBalloonTip(DisplayingNotificationTime); } if (isTweet) { isTweet = false; isTweeting = true; Thread t = new Thread(new ThreadStart(TweetThread)); t.Start(); } if (isFailEEWInit) { try { Count_Request++; GetJsonFile NetFile; NetFile = new GetJsonFile(); EQJsonFile = NetFile.GetJson("https://api.p2pquake.net/v2/jma/quake?limit=10&order=-1"); List <EQRoot> JsonData = JsonConvert.DeserializeObject <List <EQRoot> >(EQJsonFile); //TestString = "Time : " + JsonData[0].created_at; DateTime created_at; DataConverter converter = new DataConverter(); created_at = converter.GetTime(JsonData[0].created_at); if (!converter.GetTimeError()) { EQLastUpdated = created_at; isFailEQInit = false; } } catch { isFailEQInit = true; } } if (isFailEQInit) { try { Count_Request++; GetJsonFile NetFile; NetFile = new GetJsonFile(); EEWJsonFile = NetFile.GetJson("https://api.iedred7584.com/eew/json/"); EEWRoot eew = JsonConvert.DeserializeObject <EEWRoot>(EEWJsonFile); EEWLatestUNIXTime = eew.AnnouncedTime.UnixTime; if (EEWLatestUNIXTime != 0) { isFailEEWInit = false; } } catch { isFailEEWInit = true; } } }