花10分钟写的,见谅。
语音报警wav文件生成采用开源的Balabolka工具,Json解析使用Newtonsoft.Json,HTTP库采用RestSharp
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; using System.Media; using System.Timers; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using RestSharp; namespace CEIC_Forms { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Text = "中国地震台网数据"; } private void button1_Click(object sender, EventArgs e) { } public static void RunExeByProcess(string exePath, string argument) { //开启新线程 System.Diagnostics.Process process = new System.Diagnostics.Process(); //调用的exe的名称 process.StartInfo.FileName = exePath; //传递进exe的参数 process.StartInfo.Arguments = argument; process.StartInfo.UseShellExecute = false; //不显示exe的界面 process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); process.StandardInput.AutoFlush = true; process.WaitForExit(); } private void timer1_Tick(object sender, EventArgs e) { try { RestClient client = new RestClient("http://www.ceic.ac.cn/ajax/speedsearch?num=3"); RestRequest request = new RestRequest(Method.GET); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Accept-Encoding", "gzip, deflate"); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"); IRestResponse response = client.Execute(request); string jsonText = response.Content.ToString(); jsonText = jsonText.Substring(1); jsonText = jsonText.Substring(0, jsonText.Length - 1); JObject json = (JObject)JsonConvert.DeserializeObject(jsonText); JArray array = (JArray)json["shuju"]; int i = array.Count; this.textBox1.Text = ""; this.textBox2.Text = ""; this.textBox3.Text = ""; foreach (JToken jObject in array) { string aa = jObject["LOCATION_C"].ToString(); this.textBox1.Text = this.textBox1.Text + aa + "\r\n"; string bb = jObject["SYNC_TIME"].ToString(); this.textBox2.Text = this.textBox2.Text + bb + "\r\n"; string cc = jObject["M"].ToString(); this.textBox3.Text = this.textBox3.Text + cc + "\r\n"; string filetime = Convert.ToDateTime(bb).GetHashCode().ToString(); bool playtrue = false; if (!File.Exists(filetime + aa + cc + ".wav")) { playtrue = true; Form1.RunExeByProcess("D:\\Program Files\\Balabolka\\balabolka.exe", "-snq \""+ aa+ "发生里氏"+ cc+ "级地震\" \""+ filetime+ aa+ cc+ ".wav\"" ); } if (playtrue) { SoundPlayer player = new SoundPlayer(filetime + aa + cc + ".wav"); player.Play(); } } } catch { } } } }
这个挺好,如果有更实时的数据接口就能做出可视化监测的效果了你看看日本民间的这个https://www...
实话说成都那个研究所的加密接口也破解了,就是人家接口不公开,发出来不太合适。回头想办法在美观程度上再修正修正。
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。