TorontoWeatherLibA3332PO 1.0.3

dotnet add package TorontoWeatherLibA3332PO --version 1.0.3                
NuGet\Install-Package TorontoWeatherLibA3332PO -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TorontoWeatherLibA3332PO" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TorontoWeatherLibA3332PO --version 1.0.3                
#r "nuget: TorontoWeatherLibA3332PO, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TorontoWeatherLibA3332PO as a Cake Addin
#addin nuget:?package=TorontoWeatherLibA3332PO&version=1.0.3

// Install TorontoWeatherLibA3332PO as a Cake Tool
#tool nuget:?package=TorontoWeatherLibA3332PO&version=1.0.3                

TorontoWeather

The TorontoWeather project is an assignment created as part of Assignment 3 for the course 2024F CSD 3354 4 [B125] Web Applications Using C#.NET, under the guidance of the instructor. This project was developed by Preet Ojha (C0904332).

Overview

This project contains a WeatherService class that fetches weather information for Toronto using the Open-Meteo API. The service retrieves the daily maximum temperatures for Toronto and includes the corresponding day names for each temperature.


Features

  • Fetches weather data asynchronously using the Open-Meteo API.
  • Retrieves daily maximum temperatures for Toronto.
  • Includes the day of the week (e.g., Monday, Tuesday) for each temperature.
  • Parses the JSON response with Newtonsoft.Json (JObject) for easier data manipulation.

Requirements

  • .NET 5 or later.
  • Internet access to fetch data from the Open-Meteo API.
  • Newtonsoft.Json for JSON parsing.

Getting Started

Install Dependencies

Before using the WeatherService class, ensure that your project includes the necessary dependencies. Install Newtonsoft.Json via NuGet:

dotnet add package Newtonsoft.Json

Example Usage

using System;
using System.Threading.Tasks;

namespace TorontoWeather
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var weatherService = new WeatherService();
            var weatherData = await weatherService.GetTorontoWeatherAsync();

            Console.WriteLine($"Toronto Weather Data:\n{weatherData}");
        }
    }
}

How It Works

  1. WeatherService Constructor
    Initializes the HttpClient used to send HTTP requests.

  2. GetTorontoWeatherAsync() Method

    • Constructs the URL with the appropriate query parameters for latitude, longitude, daily max temperature, and timezone.
    • Sends an asynchronous GET request to fetch weather data in JSON format.
    • Returns a formatted string with the dates, day names, and corresponding maximum temperatures.
  3. ExtractMaxTemperaturesAndDays() Method

    • Extracts the daily maximum temperatures and the corresponding days from the parsed JSON response.
    • Converts the date string to a DateTime object to determine the day of the week.
    • Builds a formatted string that displays each date, its day of the week, and its corresponding maximum temperature in Celsius.

Sample Output

Toronto Weather Data:
2024-11-08 (Friday): 12.3°C
2024-11-09 (Saturday): 13.5°C
2024-11-10 (Sunday): 14.6°C
2024-11-11 (Monday): 15.2°C
2024-11-12 (Tuesday): 16.1°C

API Details

The service uses the Open-Meteo API to fetch weather data. Specifically, it requests:

  • latitude: 43.7 (Toronto's latitude).
  • longitude: -79.42 (Toronto's longitude).
  • daily: temperature_2m_max (daily maximum temperature).
  • timezone: America/Toronto (to get the weather data in the Toronto timezone).

For more information on the Open-Meteo API, visit the Open-Meteo Documentation.


Contributing

Contributions are welcome! If you have suggestions or improvements for this service, feel free to fork this repository and submit a pull request.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 94 11/17/2024
1.0.2 83 11/17/2024

Latest Version