Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9.  
  10. namespace Zadanie
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. do
  17. {
  18. Console.WriteLine("Podaj miasto:");
  19. string city = Console.ReadLine();
  20. string key = "8421655c0dd7adf4bd14640ff9f809ec", adress = $"{city}&APPID={key}&cnt=16&mode=xml";
  21. string baseadress = "http://api.openweathermap.org/data/2.5/forecast?q=";
  22.  
  23. WebClient klient = new WebClient();
  24.  
  25. try
  26. {
  27. if (File.Exists(city + ".xml") == false)
  28. klient.DownloadFile(baseadress + adress, Path.Combine(Environment.CurrentDirectory, city + ".xml"));
  29.  
  30. XmlReader xmlReader = XmlReader.Create(city + ".xml");
  31.  
  32. while (xmlReader.Read())
  33. {
  34. if (xmlReader.HasAttributes && xmlReader.NodeType == XmlNodeType.Element)
  35. {
  36. Console.WriteLine("\n\n" + xmlReader.Name.ToUpper());
  37. for (int i = 0; i < xmlReader.AttributeCount; i++)
  38. {
  39. Console.Write(xmlReader.Value + xmlReader.GetAttribute(i) + " ");
  40. }
  41. }
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Console.WriteLine($"Ups ! Wystąpił błąd: \n{e}");
  47. }
  48. Console.WriteLine("\nPogoda dla innego miasta ? Wciśnij T");
  49. } while (Console.ReadKey().Key == ConsoleKey.T);
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement