Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Copyright © 2012, Adonis S. Deliannis All rights reserved
- // Usage: (weather [ [nick], [Postal Code] ])
- public void Load(ScriptContext Context)
- {
- Context.blizzeta.SendPublicMessage("This may take some time, Please wait...");
- List<object> Args = (List<object>)Context.Arguments;
- object[] Params = Args.ToArray();
- string zip = Params[0].ToString();
- string nick = Params[1].ToString();
- Context.blizzeta.SendPublicMessage(GetWeather(zip, nick));
- }
- public string GetWeather(string PostalCode, string ToNick)
- {
- //Console.WriteLine("{0}; {1}", PostalCode, ToNick);
- string DataFolder = Environment.CurrentDirectory;
- string zip = PostalCode;
- string nick = ToNick;
- try
- {
- try
- {
- System.Xml.XmlDocument fDoc = new System.Xml.XmlDocument();
- fDoc.Load(string.Format("{0}\\Modules\\Data\\User.db", DataFolder));
- System.Xml.XmlNodeList fList = fDoc.SelectNodes("Users/User");
- foreach(System.Xml.XmlNode fNode in fList)
- {
- if(fNode.Attributes["name"].Value == zip)
- {
- zip = fNode.Attributes["postal"].Value;
- }
- }
- }
- catch
- {
- }
- System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
- xDoc.Load(string.Format("http://www.google.co.uk/ig/api?weather={0}", zip));
- System.Xml.XmlNode xCity = xDoc.SelectSingleNode("xml_api_reply/weather/forecast_information/city");
- System.Xml.XmlNode xPostal = xDoc.SelectSingleNode("xml_api_reply/weather/forecast_information/postal_code");
- System.Xml.XmlNode xCondition = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/condition");
- System.Xml.XmlNode xTempF = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/temp_f");
- System.Xml.XmlNode xTempC = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/temp_c");
- System.Xml.XmlNode xHumidity = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/humidity");
- System.Xml.XmlNode xWind = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/wind_condition");
- string City = xCity.Attributes["data"].Value;
- string Postal = xPostal.Attributes["data"].Value;
- string Condition = xCondition.Attributes["data"].Value;
- string TempF = xTempF.Attributes["data"].Value;
- string TempC = xTempC.Attributes["data"].Value;
- string Humidity = xHumidity.Attributes["data"].Value;
- string Wind = xWind.Attributes["data"].Value;
- return string.Format("{7} -> Weather for {0} {1}: {2}.C {3}.F, {4} with {5}, {6}", City, Postal, TempC, TempF, Condition, Humidity, Wind, nick );
- }
- catch(Exception ex)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(ex);
- Console.ResetColor();
- return string.Format("{0} -> Postal Code or User not found!", nick);
- }
- return "No Data Match";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement