public static void SendEmail(Aqi aqi) { MailMessage mail = new MailMessage("***REMOVED***", "<PUT E-MAIL HERE>"); SmtpClient client = new SmtpClient() { Host = "mail.c**k.li", Port = 587, EnableSsl = true, Timeout = 100, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential("***REMOVED***", "***REMOVED***") }; mail.Subject = $"Pollutometer warning - {DateTime.Now}"; mail.IsBodyHtml = true; mail.Body = "<h3>WARNING!</h3>\n" + "\n" + "<img src=\"https://i.imgflip.com/20b4q2.jpg\"/>\n" + "\n" + $"<p>The warning was triggered by {aqi.GasName}.</p>\n" + $"<p>Air quality index: {aqi.Value}</p>" + $"<p>The AQI level is {aqi.Level}!"; client.Send(mail); }
private async Task <string> GetWeather(string cityname) { WeatherData weatherdata = await GetWeatherDataAsync(cityname); if (weatherdata == null || weatherdata.HeWeather5 == null) { return(string.Format("无法获取\"{0}\"的天气信息", cityname)); } else { Heweather5[] weatherServices = weatherdata.HeWeather5; if (weatherServices.Length <= 0) { return(string.Format("无法获取\"{0}\"的天气信息", cityname)); } Basic cityInfo = weatherServices[0].basic; if (cityInfo == null) { return(string.Format("\"{0}\"应该不是城市的名字", cityname)); } string cityInfoString = "城市:" + cityInfo.city + "\r\n"; Now cityNowInfo = weatherServices[0].now; string cityNowInfoString = "现在天气:" + cityNowInfo.cond.txt + "\r\n" + "现在温度:" + cityNowInfo.tmp; Suggestion citySuggestionInfo = weatherServices[0].suggestion; string citySuggestionInfoString = "舒适指数:" + citySuggestionInfo.comf.brf + "\r\n" + "穿衣建议:" + citySuggestionInfo.drsg.txt + "\r\n" + "运动建议:" + citySuggestionInfo.sport.txt + "\r\n"; Aqi cityAqiInfo = weatherServices[0].aqi; string cityAqiInfoString = "空气质量指数:" + cityAqiInfo.city.aqi + "\r\n" + "PM2.5:" + cityAqiInfo.city.pm25; return(string.Format("现在{0}的天气:\r\n{1}", cityname, cityInfoString + cityNowInfoString + cityAqiInfoString + citySuggestionInfoString)); } }
public void SendEmailTest() { var aqi = new Aqi { GasName = "SO", Value = 69, Level = "Moderate" }; EmailSender.SendEmail(aqi); }
private async Task <string> GetWeather(string cityname) { WeatherData weatherdata = await MengmengBotTask.GetWeatherAsync(cityname); if (weatherdata == null || weatherdata.HeWeatherdataservice30 == null) { return(string.Format("呃。。。萌萌不知道\"{0}\"这个城市的天气信息", cityname)); } else { HeweatherDataService30[] weatherServices = weatherdata.HeWeatherdataservice30; if (weatherServices.Length <= 0) { return(string.Format("呃。。。萌萌不知道\"{0}\"这个城市的天气信息", cityname)); } Basic cityinfo = weatherServices[0].basic; if (cityinfo == null) { return(string.Format("呃。。。萌萌目测\"{0}\"这个应该不是一个城市的名字。。不然我咋不知道呢。。。", cityname)); } String cityinfoString = "城市信息:" + cityinfo.city + "\r\n" + "更新时间:" + cityinfo.update.loc + "\r\n" + "经纬度:" + cityinfo.lat + "," + cityinfo.lon + "\r\n"; Aqi cityAirInfo = weatherServices[0].aqi; String airInfoString = "空气质量指数:" + cityAirInfo.city.aqi + "\r\n" + "PM2.5 1小时平均值:" + cityAirInfo.city.pm25 + "(ug/m³)\r\n" + "PM10 1小时平均值:" + cityAirInfo.city.pm10 + "(ug/m³)\r\n" + "二氧化硫1小时平均值:" + cityAirInfo.city.so2 + "(ug/m³)\r\n" + "二氧化氮1小时平均值:" + cityAirInfo.city.no2 + "(ug/m³)\r\n" + "一氧化碳1小时平均值:" + cityAirInfo.city.co + "(ug/m³)\r\n"; Suggestion citySuggestion = weatherServices[0].suggestion; String suggestionString = "生活指数:" + "\r\n" + "穿衣指数:" + citySuggestion.drsg.txt + "\r\n" + "紫外线指数:" + citySuggestion.uv.txt + "\r\n" + "舒适度指数:" + citySuggestion.comf.txt + "\r\n" + "旅游指数:" + citySuggestion.trav.txt + "\r\n" + "感冒指数:" + citySuggestion.flu.txt + "\r\n"; Daily_Forecast[] cityDailyForecast = weatherServices[0].daily_forecast; Now cityNowStatus = weatherServices[0].now; String nowStatusString = "天气实况:" + "\r\n" + "当前温度(摄氏度):" + cityNowStatus.tmp + "\r\n" + "体感温度:" + cityNowStatus.fl + "\r\n" + "风速:" + cityNowStatus.wind.spd + "(Kmph)\r\n" + "湿度:" + cityNowStatus.hum + "(%)\r\n" + "能见度:" + cityNowStatus.vis + "(km)\r\n"; return(string.Format("现在{0}天气实况:\r\n{1}", cityname, cityinfoString + nowStatusString + airInfoString + suggestionString)); } }
public static Aqi CalculateAqi(Reading reading) { double[,,] breakpoints = { { { 0, 4.4 }, { 4.5, 9.4 }, { 9.5, 12.4 }, { 12.5, 15.4 }, { 15.5, 30.4 }, { 30.5, 40.4 }, { 40.5, 50.4 } }, { { 0.000, 0.034 }, { 0.035, 0.144 }, { 0.145, 0.224 }, { 0.225, 0.304 }, { 0.305, 0.604 }, { 0.605, 0.804 }, { 0.805, 1.004 } }, { { 0, 0.05 }, { 0.08, 0.10 }, { 0.15, 0.20 }, { 0.25, 0.31 }, { 0.65, 1.24 }, { 1.25, 1.64 }, { 1.65, 2.04 } }, { { 0, 50 }, { 51, 100 }, { 101, 150 }, { 151, 200 }, { 201, 300 }, { 301, 400 }, { 401, 500 } } }; double i, c = 0, cLow = 0, cHigh = 0, iLow = 0, iHigh = 0; Aqi aqi = new Aqi(); for (int x = 0; x < 4; x++) { switch (x) { case 0: c = reading.Co; break; case 1: c = reading.So; break; case 2: c = reading.No; break; } for (int y = 0; y < 7; y++) { if (c >= breakpoints[x, y, 0] && c <= breakpoints[x, y, 1]) { cLow = breakpoints[x, y, 0]; cHigh = breakpoints[x, y, 1]; iLow = breakpoints[3, y, 0]; iHigh = breakpoints[3, y, 1]; break; } } i = (iHigh - iLow) / (cHigh - cLow) * (c - cLow) + iLow; if (i > aqi.Value) { aqi.Value = i; switch (x) { case 0: aqi.GasName = "CO"; break; case 1: aqi.GasName = "SO"; break; case 2: aqi.GasName = "NO"; break; } } } return(aqi); }