Advertisement
Blizzardo1

Weather.cs

Jul 10th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. Copyright © 2012, Adonis S. Deliannis All rights reserved
  2. // Usage: (weather [ [nick], [Postal Code] ])
  3.  
  4. public void Load(ScriptContext Context)
  5. {
  6.     Context.blizzeta.SendPublicMessage("This may take some time, Please wait...");
  7.     List<object> Args = (List<object>)Context.Arguments;
  8.     object[] Params = Args.ToArray();
  9.     string zip = Params[0].ToString();
  10.     string nick = Params[1].ToString();
  11.    
  12.    
  13.     Context.blizzeta.SendPublicMessage(GetWeather(zip, nick));
  14.  
  15. }
  16.  
  17. public string GetWeather(string PostalCode, string ToNick)
  18. {
  19.     //Console.WriteLine("{0}; {1}", PostalCode, ToNick);
  20.     string DataFolder = Environment.CurrentDirectory;
  21.     string zip = PostalCode;
  22.     string nick = ToNick;
  23.     try
  24.     {
  25.         try
  26.         {
  27.             System.Xml.XmlDocument fDoc = new System.Xml.XmlDocument();
  28.             fDoc.Load(string.Format("{0}\\Modules\\Data\\User.db", DataFolder));
  29.             System.Xml.XmlNodeList fList = fDoc.SelectNodes("Users/User");
  30.             foreach(System.Xml.XmlNode fNode in fList)
  31.             {
  32.                 if(fNode.Attributes["name"].Value == zip)
  33.                 {
  34.                     zip = fNode.Attributes["postal"].Value;
  35.                 }
  36.             }
  37.         }
  38.         catch
  39.         {
  40.            
  41.         }
  42.         System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
  43.         xDoc.Load(string.Format("http://www.google.co.uk/ig/api?weather={0}", zip));
  44.         System.Xml.XmlNode xCity = xDoc.SelectSingleNode("xml_api_reply/weather/forecast_information/city");
  45.         System.Xml.XmlNode xPostal = xDoc.SelectSingleNode("xml_api_reply/weather/forecast_information/postal_code");
  46.         System.Xml.XmlNode xCondition = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/condition");
  47.         System.Xml.XmlNode xTempF = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/temp_f");
  48.         System.Xml.XmlNode xTempC = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/temp_c");
  49.         System.Xml.XmlNode xHumidity = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/humidity");
  50.         System.Xml.XmlNode xWind = xDoc.SelectSingleNode("xml_api_reply/weather/current_conditions/wind_condition");
  51.  
  52.         string City = xCity.Attributes["data"].Value;
  53.         string Postal = xPostal.Attributes["data"].Value;
  54.         string Condition = xCondition.Attributes["data"].Value;
  55.         string TempF = xTempF.Attributes["data"].Value;
  56.         string TempC = xTempC.Attributes["data"].Value;
  57.         string Humidity = xHumidity.Attributes["data"].Value;
  58.         string Wind = xWind.Attributes["data"].Value;
  59.         return string.Format("{7} -> Weather for {0} {1}: {2}.C {3}.F, {4} with {5}, {6}", City, Postal, TempC, TempF, Condition, Humidity, Wind, nick );
  60.     }
  61.     catch(Exception ex)
  62.     {
  63.    
  64.         Console.ForegroundColor = ConsoleColor.Red;
  65.         Console.WriteLine(ex);
  66.         Console.ResetColor();
  67.         return string.Format("{0} -> Postal Code or User not found!", nick);
  68.     }
  69.     return "No Data Match";
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement