Skip to content

Commit

Permalink
added usage
Browse files Browse the repository at this point in the history
  • Loading branch information
suvanbanerjee committed Mar 15, 2024
1 parent 6dabc98 commit ee7cb7d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
67 changes: 64 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 ☀️
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions test/test_current_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions test/test_daily_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ee7cb7d

Please sign in to comment.