-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more data #111
Add more data #111
Conversation
Reviewer's Guide by SourceryThis pull request adds functionality to fetch and print hourly weather data, including cloud cover and visibility. The get_hourly_forecast function was created to fetch the data, and the gather_data function was updated to include this data in the ocean_data_dict. The print_outputs function was modified to call a new print_hourly_data function, and the CLI was updated to handle the new data. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MylesPerHour201 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider making the new 'show_visibility' and 'show_cloud_cover' arguments in the arguments_dictionary function configurable rather than hard-coding them to 1.
- The addition of hourly forecast data is a good feature, but consider the potential impact on API usage and performance. You might want to implement caching for this data to reduce API calls.
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
src/api.py
Outdated
@@ -294,6 +295,62 @@ def forecast(lat, long, decimal, days=0): | |||
return forecast_data | |||
|
|||
|
|||
def get_hourly_forecast(lat, long, days=1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider adding error handling for API calls and data processing
The function currently doesn't handle potential exceptions from API calls or data processing. Adding try-except blocks would make the function more robust and prevent unexpected crashes.
def get_hourly_forecast(lat, long, days=1):
try:
# API call and data processing here
pass
except requests.RequestException as e:
logging.error(f"API request failed: {e}")
return None
except ValueError as e:
logging.error(f"Data processing error: {e}")
return None
src/helper.py
Outdated
""" | ||
Basically the main printing function, | ||
calls all the other printing functions | ||
""" | ||
print("\n") | ||
if city == "No data": | ||
print("No location found") | ||
# if city == "No data": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Remove commented-out code
If this code is no longer needed, it should be removed entirely rather than left commented out. This improves code readability and maintainability.
# if city == "No data": | |
if ocean_data_dict["Height"] == "No data": |
src/cli.py
Outdated
@@ -42,11 +42,14 @@ def run(lat=0, long=0, args=None): | |||
# Makes calls to the apis(ocean, UV) and returns the values in a dictionary | |||
ocean_data_dict = api.gather_data(lat, long, arguments) | |||
|
|||
# Sets hourly_dict = the dictionary for hourly weather data | |||
curr_hour_data = api.get_hourly_forecast(lat, long, days=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Maintain consistent variable naming
The variable 'curr_hour_data' is set here, but it's passed as 'curr_hour' to print_outputs. Consider using consistent naming to improve code clarity.
hourly_forecast = api.get_hourly_forecast(lat, long, days=1)
Hey @MylesPerHour201 Nice work. I'm going to review your PR later today In the meantime, can you fix the linter issues? The test failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look great! I left a couple comments on some changes I think would be necessary
Also, the readme should be updated to reflect the new arguments (like show_cloud_cover
/scc
or show_vis
/sv
)
Let me know if this all makes sense
src/helper.py
Outdated
@@ -40,6 +40,8 @@ def arguments_dictionary(lat, long, city, args): | |||
"forecast_days": get_forecast_days(args), | |||
"color": get_color(args), | |||
"gpt": 0, | |||
"show_visibility": 1, | |||
"show_cloud_cover": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should set these to 0 as default, and show them if the user specifies in a cli argument (like show_vis
or sv
)
src/api.py
Outdated
"latitude": lat, | ||
"longitude": long, | ||
"hourly": ["cloud_cover", "visibility"], | ||
"temperature_unit": "fahrenheit", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to pass in an argument that specifies the temperature unit. We can default to Fahrenheit. If the user passes the metric
argument, Celsius should be shown.
See the ocean_information
function to get an idea
@@ -312,6 +368,8 @@ def gather_data(lat, long, arguments): | |||
|
|||
wind_temp = current_wind_temp(lat, long, arguments["decimal"]) | |||
|
|||
hourly_dict = get_hourly_forecast(lat, long, arguments["decimal"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You call get_hourly_forecast
here and also in cli.py
. It should only be called here, in gather_data
src/cli.py
Outdated
@@ -42,11 +42,14 @@ def run(lat=0, long=0, args=None): | |||
# Makes calls to the apis(ocean, UV) and returns the values in a dictionary | |||
ocean_data_dict = api.gather_data(lat, long, arguments) | |||
|
|||
# Sets hourly_dict = the dictionary for hourly weather data | |||
hourly_forecast = api.get_hourly_forecast(lat, long, days=1) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call api.get_hourly_forecast
already in api.gather_data()
above
src/cli.py
Outdated
# Non-JSON output | ||
if arguments["json_output"] == 0: | ||
# Response prints all the outputs & returns the GPT response | ||
response = helper.print_outputs( | ||
city, ocean_data_dict, arguments, gpt_prompt, gpt_info | ||
hourly_forecast, ocean_data_dict, arguments, gpt_prompt, gpt_info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ocean_data_dict
should have all the hourly forecast data, if im not mistaken. It doesn't seem necessary to pass it as an argument
src/helper.py
Outdated
@@ -379,3 +386,16 @@ def print_gpt(surf_data, gpt_prompt, gpt_info): | |||
else: | |||
gpt_response = gpt.openai_gpt(summary, gpt_prompt, api_key, gpt_model) | |||
return gpt_response | |||
|
|||
|
|||
def print_hourly_data(curr_hour): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function ever used? I commented it out when testing and everything (as far as I can tell) still functions properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think it is now with the newest changes based on your suggestions. Would you like me to remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please, once thats done I'll merge the PR
@all-contributors please add @MylesPerHour201 for code |
I've put up a pull request to add @MylesPerHour201! 🎉 |
Fixes #4
Summary by Sourcery
Add functionality to retrieve and display hourly weather data, including cloud cover and visibility. Enhance existing data gathering and output functions to incorporate the new hourly data. Fix linter issue by removing unnecessary 'city' parameter from print_outputs function.
New Features:
Bug Fixes:
Enhancements: