/// <summary> /// 处理请求 /// </summary> /// <returns></returns> public string HandleRequest() { string response = string.Empty; TextMessage tm = TextMessage.LoadFromXml(RequestXml); string content = tm.Content.Trim(); if (string.IsNullOrEmpty(content)) { response = "您什么都没输入,没法帮您啊,%>_<%。"; } else { if (content.StartsWith("tq", StringComparison.OrdinalIgnoreCase)) { string cityName = content.Substring(2).Trim(); response = WeatherHelper.GetWeather(cityName); } else { response = HandleOther(content); } } tm.Content = response; //进行发送者、接收者转换 string temp = tm.ToUserName; tm.ToUserName = tm.FromUserName; tm.FromUserName = temp; response = tm.GenerateContent(); return(response); }
public async void Weather(MessageEventArgs messageEventArgs) { var weather = await WeatherHelper.GetWeather(User.GetLanguage); var inlineKeyboard = TemplateModelsBuilder.RefreshWeather(User.GetLanguage); SendMessageAsync(ChatId, weather, ParseMode.Markdown, replyMarkup: inlineKeyboard); }
/// <summary> /// 查询天气 /// </summary> /// <param name="cityName"></param> /// <param name="em"></param> /// <returns></returns> private string searchWeather(string cityName, EventMessage em) { TextMessage tm = new TextMessage(); tm.Content = WeatherHelper.GetWeather(cityName); //进行发送者、接收者转换 tm.ToUserName = em.FromUserName; tm.FromUserName = em.ToUserName; tm.CreateTime = Common.GetNowTime(); return(tm.GenerateContent()); }
static void Main(string[] args) { Console.WriteLine("控制台程序已启动,输入Q/q退出程序!"); string txt = string.Empty; while (!(txt = Console.ReadLine()).ToUpper().Equals("Q")) { if (txt.ToUpper().Equals("A")) { WeatherHelper weatherHelper = new WeatherHelper("yzwniowtxrdeejan"); //var info = weatherHelper.GetWeather("武汉"); var info = weatherHelper.GetWeather("霍尔果斯"); } } }
private void OnTimedEvent(object source, ElapsedEventArgs e) { if (DateTime.Now.Minute == 0) { string weatherInfo = WeatherHelper.GetWeather(); Dispatcher.BeginInvoke(new Action(delegate { this.txtWeather.Text = weatherInfo; })); } Dispatcher.BeginInvoke(new Action(delegate { this.txtDate.Text = DateTime.Now.ToString("yyyy年 MM月dd日"); this.txtTime.Text = DateTime.Now.ToString("HH:mm"); })); }
//Refresh weather public async void RefreshWeather(CallbackQueryEventArgs callbackQueryEventArgs) { var args = ArgParser.ParseCallbackData(callbackQueryEventArgs.CallbackQuery.Data); bool isEdit = args.ContainsKey(Commands.IsEdit); var weather = await WeatherHelper.GetWeather(User.GetLanguage); var inlineKeyboard = TemplateModelsBuilder.RefreshWeather(User.GetLanguage); if (isEdit) { EditMessageTextAsync(ChatId, MessageId, weather, ParseMode.Markdown, replyMarkup: inlineKeyboard); } else { SendMessageAsync(ChatId, weather, ParseMode.Markdown, replyMarkup: inlineKeyboard); } }
private async void Get_Weather() { List <WeatherDetails> weathers = await WeatherHelper.GetWeather(); WeatherDetails weatherDetails = weathers.First(); BitmapImage bi3 = new BitmapImage(); bi3.BeginInit(); bi3.UriSource = new Uri(weatherDetails.WeatherIcon, UriKind.Relative); bi3.EndInit(); ImgWeather.Stretch = Stretch.Fill; ImgWeather.Source = bi3; CurrentTemp.Text = weatherDetails.Temperature; MaxTemp.Text = weatherDetails.MaxTemperature; MinTemp.Text = weatherDetails.MinTemperature; Wind.Text = weatherDetails.WindSpeed; Dayofweek.Text = weatherDetails.WeatherDay; }
static void Main(string[] args) { Console.WriteLine("控制台程序已启动,输入Q/q退出程序!"); string txt = string.Empty; while (!(txt = Console.ReadLine()).ToUpper().Equals("Q")) { if (txt.ToUpper().Equals("A")) { WeatherHelper weatherHelper = new WeatherHelper("yzwniowtxrdeejan"); //var info = weatherHelper.GetWeather("武汉"); var info = weatherHelper.GetWeather("霍尔果斯"); } if (txt.ToUpper().Equals("T")) { //new LogT1().Test(); //new LogT1().Test1(); new ColorTest().SaveAllColorToBmp(@"D:\AllColor.bmp"); } } }
public MainWindow() { InitializeComponent(); //this.CoursePart.ImageSource = new BitmapImage(new Uri("book-icon.png", UriKind.Relative)); //先将图片右键生成操作设置成resource this.TeacherPart.ImageSource = new BitmapImage(new Uri("ceateacher.png", UriKind.Relative)); this.RoomPart.ImageSource = new BitmapImage(new Uri("ceaclass.png", UriKind.Relative)); this.StudentPart.ImageSource = new BitmapImage(new Uri("ceastudent.png", UriKind.Relative)); this.TeacherPart.SelectedImageSource = new BitmapImage(new Uri("ceateacherselected.png", UriKind.Relative)); this.RoomPart.SelectedImageSource = new BitmapImage(new Uri("ceaclassselected.png", UriKind.Relative)); this.StudentPart.SelectedImageSource = new BitmapImage(new Uri("ceastudentselected.png", UriKind.Relative)); //this.CoursePart.ButtonClick += CoursePart_ButtonClick; this.RoomPart.ButtonClick += RoomPart_ButtonClick; this.TeacherPart.ButtonClick += TeacherPart_ButtonClick; this.StudentPart.ButtonClick += StudentPart_ButtonClick; imageWX.Source = new BitmapImage(new Uri("Images/ceawxgzh.png", UriKind.Relative)); if (System.Configuration.ConfigurationManager.AppSettings["IsDev"] == "true") { this.Topmost = false; } //时间天气信息 string weatherInfo = WeatherHelper.GetWeather(); this.txtDate.Text = DateTime.Now.ToString("yyyy年 MM月dd日"); this.txtTime.Text = DateTime.Now.ToString("HH:mm"); this.txtWeather.Text = weatherInfo; aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = 1000 * 60; aTimer.Start(); }
public static void GetWeather() { var data = WeatherHelper.GetWeather(); }
public async Task Execute() { if (User == null) { await Bot.AnswerInlineQueryAsync(inlineQueryId : InlineQueryEventArgs.InlineQuery.Id, results : new InlineQueryResultBase[] { }, switchPmParameter : "start", switchPmText : "Start bot"); return; } //check if user banned! if (User.IsBanned()) { return; } var weather = await WeatherHelper.GetWeather(User.GetLanguage); weather = weather.Replace("_", "\\_"); InlineQueryResultBase[] results = { // displayed result new InlineQueryResultArticle( id: "0", title: Local.Weather[User.GetLanguage], inputMessageContent: new InputTextMessageContent(weather) { ParseMode = ParseMode.Markdown } ), new InlineQueryResultArticle( id: "1", title: $"{Local.TodayTo[User.GetLanguage]} CTIR", inputMessageContent: new InputTextMessageContent(ScheduleHelper.GenerateSchedule(DateTime.Today, Way.ToCTIR, User.GetLanguage).Replace("_", "\\_")) { ParseMode = ParseMode.Markdown } ), new InlineQueryResultArticle( id: "2", title: $"{Local.TodayTo[User.GetLanguage]} Rzeszow", inputMessageContent: new InputTextMessageContent(ScheduleHelper.GenerateSchedule(DateTime.Today, Way.ToRzeszow, User.GetLanguage).Replace("_", "\\_")) { ParseMode = ParseMode.Markdown } ), new InlineQueryResultArticle( id: "3", title: $"{Local.TomorrowTo[User.GetLanguage]} CTIR", inputMessageContent: new InputTextMessageContent(ScheduleHelper.GenerateSchedule(DateTime.Today.AddDays(1),Way.ToCTIR, User.GetLanguage).Replace("_", "\\_")) { ParseMode = ParseMode.Markdown } ), new InlineQueryResultArticle( id: "4", title: $"{Local.TomorrowTo[User.GetLanguage]} Rzeszow", inputMessageContent: new InputTextMessageContent(ScheduleHelper.GenerateSchedule(DateTime.Today.AddDays(1),Way.ToRzeszow, User.GetLanguage).Replace("_", "\\_")) { ParseMode = ParseMode.Markdown } ) }; await Bot.AnswerInlineQueryAsync(inlineQueryId : InlineQueryEventArgs.InlineQuery.Id, results : results, cacheTime : 300); }
public bool SetAirportWeather() { bool result = true; try { List <APIKey> Keys = new List <APIKey>(); Keys.Add(new APIKey("490e854a3514ea0f7f1810463dabc647")); Keys.Add(new APIKey("1df9017a2a7dba1a7d71f38cfecefb54")); Keys.Add(new APIKey("9cdd30b4010b31748a8525bc8b334e60")); Keys.Add(new APIKey("35f7cb7530eb07d0f3b47ca49182445d")); Keys.Add(new APIKey("6841a3f8d7d154552d2605d7be209351")); Keys.Add(new APIKey("5f12421d192dea47c28585df8eccafd6")); Keys.Add(new APIKey("8ae34f0b0046acdef3f1355c1317e50f")); Keys.Add(new APIKey("3dc43f217289d59c9d068b4d8a72f81b")); Keys.Add(new APIKey("159b8f6f025859c35b579033213d7695")); Keys.Add(new APIKey("5f373aa939f7c088a043051941357de6")); Keys.Add(new APIKey("b0fd8436af42202a5849cfb1e70af9b6")); Keys.Add(new APIKey("be3336318ad232ff56defc4588295f27")); Keys.Add(new APIKey("1e91dbdda7efef52c832979aea8dab66")); Keys.Add(new APIKey("f86051b3243ed66e705cce8f434f0e0b")); Keys.Add(new APIKey("a2257d9a0af19152e2c6cfccbc3fa498")); Keys.Add(new APIKey("763a4c51d0afce69a17891e9ffc9dbb4")); Keys.Add(new APIKey("d205806e3d5a1d900859cc3d82febb96")); Keys.Add(new APIKey("7b9995c4df3be3df39053f4df6f74965")); Keys.Add(new APIKey("566b55cfeee56e43136a17e3bb7896c5")); Keys.Add(new APIKey("fada50cfd88b7364f0de7272c0446f90")); Keys.Add(new APIKey("1dc8c93c862d080d435e23e8441a4a5f")); Keys.Add(new APIKey("ad8e91aa8511ac2e68a28b43670d94db")); Keys.Add(new APIKey("703708d9bb26be5db461cb55df9c322a")); Keys.Add(new APIKey("6c68181da024a1e6ffe067bb91ba81cd")); Keys.Add(new APIKey("bd3fded169268ba8af871490c0db3990")); Keys.Add(new APIKey("a99f8b9cab49975c659a27f9830557df")); Keys.Add(new APIKey("acfce707d4ae405210e032e63f260b2d")); Keys.Add(new APIKey("1ea3d77ef1f1086da23b08bfeaa126d1")); Keys.Add(new APIKey("de854affd68a2fca04670f309945d1e5")); Keys.Add(new APIKey("f6b966f0b40949d8d5f6f64f7ea1f7fe")); Keys.Add(new APIKey("3738d4cf9a5225703577fde59ef21d72")); Keys.Add(new APIKey("c3085013199ba2d249405f5506eaa0f5")); Keys.Add(new APIKey("c37cc8d06de6118f10372198e4f1eca9")); Keys.Add(new APIKey("1583cf425f7255ad532249ba590152e3")); Keys.Add(new APIKey("d354ca951d6d7f556ec8cd171a2d357c")); List <Airport> Airports = _airportRepo.FindAllBy(a => a.Active).OrderBy(ra => ra.Id).ToList(); //Airports = Airports.Where(a => a.Id == 7921 || a.Id == 2565).ToList(); DateTime Start = new DateTime(2015, 01, 01); DateTime End = new DateTime(2017, 12, 31); DateTime LastDataFetched = _historicWeatherRepo.List()?.OrderByDescending(h => h.Date)?.FirstOrDefault()?.Date ?? Start; DateTime Date = LastDataFetched; bool MaxAPIRequestsReached = false; while (Date <= End && !MaxAPIRequestsReached) { string UnixDate = DateHelper.GetUnixTimeStamp(Date); foreach (var airport in Airports) { if (Date > LastDataFetched || (!_historicWeatherRepo.FindAllBy(w => w.AirportId == airport.Id && w.Date == Date).Any())) { try { if (airport.Longitude != 0 && airport.Latitude != 0) { APIKey KeyToUse = Keys.Where(k => k.RequestsNumber < 1000).OrderBy(k => k.RequestsNumber).FirstOrDefault(); if (KeyToUse != null) { HistoricWeatherItem weather = WeatherHelper.GetWeather(airport.Latitude.Value, airport.Longitude.Value, UnixDate, KeyToUse.Key); Keys.Where(k => k.Key == KeyToUse.Key).FirstOrDefault().RequestsNumber = KeyToUse.RequestsNumber + 1; AddHistoricWeather(weather, Date, airport.Id); } else { // We stop MaxAPIRequestsReached = true; } } } catch (Exception e2) { result = false; Commons.Logger.GenerateError(e2, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Airport weather Loop, Id = " + airport.Id); } } } Date = Date.AddDays(1); } } catch (Exception e) { result = false; Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); } return(result); }
private async void GetWeatherConditions() { Query = string.Empty; Weather = await WeatherHelper.GetWeather(SelectedCity.Key); }