Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- namespace Zadanie
- {
- class Program
- {
- static void Main(string[] args)
- {
- do
- {
- Console.WriteLine("Podaj miasto:");
- string city = Console.ReadLine();
- string key = "8421655c0dd7adf4bd14640ff9f809ec", adress = $"{city}&APPID={key}&cnt=16&mode=xml";
- string baseadress = "http://api.openweathermap.org/data/2.5/forecast?q=";
- WebClient klient = new WebClient();
- try
- {
- if (File.Exists(city + ".xml") == false)
- klient.DownloadFile(baseadress + adress, Path.Combine(Environment.CurrentDirectory, city + ".xml"));
- XmlReader xmlReader = XmlReader.Create(city + ".xml");
- while (xmlReader.Read())
- {
- if (xmlReader.HasAttributes && xmlReader.NodeType == XmlNodeType.Element)
- {
- Console.WriteLine("\n\n" + xmlReader.Name.ToUpper());
- for (int i = 0; i < xmlReader.AttributeCount; i++)
- {
- Console.Write(xmlReader.Value + xmlReader.GetAttribute(i) + " ");
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine($"Ups ! Wystąpił błąd: \n{e}");
- }
- Console.WriteLine("\nPogoda dla innego miasta ? Wciśnij T");
- } while (Console.ReadKey().Key == ConsoleKey.T);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement