From ee7cb7df10f4195747c52080f94b4b3b519754dc Mon Sep 17 00:00:00 2001 From: suvanbanerjee Date: Fri, 15 Mar 2024 10:40:41 +0530 Subject: [PATCH] added usage --- README.md | 67 ++++++++++++++++++++++++++++++++++-- test/test_current_weather.py | 5 --- test/test_daily_weather.py | 5 --- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f66b4f4..46516ae 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # WeatherKit ☀️ ## What is It? -WeatherKit is a python pacakge that provides a simple interface to get weather data without any API key or any other credentials. It is a simple and easy to use package that provides the current weather data of any location in the world. It can get weather details from address, city, country, or even from the latitude and longitude of the location. +WeatherKit is a python pacakge that provides a simple interface to get weather data without any API key or any other credentials. It is a simple and easy to use package that provides the current weather data of any location in the world. It can get weather details from address, city, country, or latitude and longitude of the location. Currently it Provies the following weather details for current time and forecast for 7 days: - Temperature ☀️ @@ -36,8 +36,69 @@ Install the package using the following command: pip install dist/*.whl ``` -## Documentation -The documentation of WeatherKit can be found [here](example.com) +## Usage +### Current Weather +Sample usage providing city name +```python +import weatherkit +NYC = weatherkit.current_weather('New York') +print(NYC.temperature()) +# Output: 20.0 +print(NYC.temperature(units='imperial')) +# Output: 68.0 +print(NYC.humidity()) +# Output: 50 +print(NYC.weather_code()) +# Output: 3 +print(NYC.precipitation()) +# Output: 0.0 +``` +Sample usage providing latitude and longitude + +```python +import weatherkit +NYC = weatherkit.current_weather(40.7128, -74.0060) +print(NYC.temperature()) +# Output: 20.0 +print(NYC.temperature(units='imperial')) +# Output: 68.0 +print(NYC.humidity()) +# Output: 50 +print(NYC.weather_code()) +# Output: 3 +print(NYC.precipitation()) +# Output: 0.0 +``` +### Daily Forecast +Sample usage providing city name +```python +import weatherkit +NYC = weatherkit.daily_forecast('New York') +print(NYC.max_temperature()) +# Output: 20.0 +print(NYC.max_temperature(units='imperial')) +# Output: 68.0 +print(NYC.min_temperature()) +# Output: 10.0 +print(NYC.max_temperature(day_offset=3)) +# Output: 20.0 +print(NYC.max_temperature(day_offset=3, units='imperial')) +# Output: 68.0 +print(NYC.prediction_sum()) +# Output: 0.0 +print(NYC.prediction_sum(day_offset=3)) +# Output: 3.2 +print(NYC.prediction_sum(units='imperial')) +# Output: 0.0 (in Inches) +print(NYC.weather_code()) +# Output: 3 +print(NYC.weather_code(day_offset=3)) +# Output: 3 +``` +#### Note +- Similar to current weather, daily forecast can also be used by providing latitude and longitude. + +- day_offset is the number of days from today for which the forecast is required. day_offset=0 (which is default) will give the forecast for today, day_offset=1 will give the forecast for tomorrow and so on. ## Contributing Contributions are welcome, and they are greatly appreciated! just fork the repository, make changes and create a pull request. diff --git a/test/test_current_weather.py b/test/test_current_weather.py index 4ccbf34..9d4d794 100644 --- a/test/test_current_weather.py +++ b/test/test_current_weather.py @@ -3,31 +3,26 @@ class TestCurrentWeather(unittest.TestCase): def setUp(self): - # Create an instance of current_weather with latitude and longitude self.weather = current_weather(37.7749, -122.4194) def test_temperature(self): - # Test getting the current temperature temperature = self.weather.temperature() self.assertIsInstance(temperature, float) self.assertGreaterEqual(temperature, -100) self.assertLessEqual(temperature, 100) def test_humidity(self): - # Test getting the current humidity humidity = self.weather.humidity() self.assertIsInstance(humidity, int) self.assertGreaterEqual(humidity, 0) self.assertLessEqual(humidity, 100) def test_precipitation(self): - # Test getting the current precipitation precipitation = self.weather.precipitation() self.assertIsInstance(precipitation, float) self.assertGreaterEqual(precipitation, 0) def test_weather_code(self): - # Test getting the current weather code weather_code = self.weather.weather_code() self.assertIsInstance(weather_code, int) self.assertGreaterEqual(weather_code, 0) diff --git a/test/test_daily_weather.py b/test/test_daily_weather.py index 33bde1a..a29a0b9 100644 --- a/test/test_daily_weather.py +++ b/test/test_daily_weather.py @@ -3,31 +3,26 @@ class TestDailyWeather(unittest.TestCase): def setUp(self): - # Create an instance of daily_weather with latitude and longitude self.weather = daily_weather(37.7749, -122.4194) def test_max_temperature(self): - # Test getting the maximum temperature temperature = self.weather.max_temperature() self.assertIsInstance(temperature, float) self.assertGreaterEqual(temperature, -100) self.assertLessEqual(temperature, 100) def test_min_temperature(self): - # Test getting the minimum temperature temperature = self.weather.min_temperature() self.assertIsInstance(temperature, float) self.assertGreaterEqual(temperature, -100) self.assertLessEqual(temperature, 100) def test_precipitation_sum(self): - # Test getting the precipitation sum precipitation = self.weather.precipitation_sum() self.assertIsInstance(precipitation, float) self.assertGreaterEqual(precipitation, 0) def test_weather_code(self): - # Test getting the weather code weather_code = self.weather.weather_code() self.assertIsInstance(weather_code, int) self.assertGreaterEqual(weather_code, 0)