-
Notifications
You must be signed in to change notification settings - Fork 0
test delete overview comment 1 #8
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
base: 3File
Are you sure you want to change the base?
Changes from all commits
222e4cb
5657941
6eaf052
0637a41
2ae64a6
5dd0d5b
9989a72
51118c2
eebf96e
9570eb3
745a285
ce1f66f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| # Python-examples | ||
| # Python-examples | ||
| Python code |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,23 +4,19 @@ | |||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||
| from datetime import datetime | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def time_from_utc_with_timezone(utc_with_tz): | ||||||||||||||||||||||||||||||||||||
| from datetime import timezone | ||||||||||||||||||||||||||||||||||||
| local_time = datetime.fromtimestamp(utc_with_tz, tz=timezone.utc) | ||||||||||||||||||||||||||||||||||||
| return local_time.time() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # asking the user for api key | ||||||||||||||||||||||||||||||||||||
| api_key = input("Please Enter Your API: ") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| #asking the user for city name | ||||||||||||||||||||||||||||||||||||
| city_name = input("Please Enter Your City Name: ") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Register yourself here and get the API key first: openweathermap.org | ||||||||||||||||||||||||||||||||||||
| # API Key would be something like this: 2f8b2c69352e89120becd33028a1c986 | ||||||||||||||||||||||||||||||||||||
| # We have to call Current weather data API: https://openweathermap.org/current (There are many APIs there) | ||||||||||||||||||||||||||||||||||||
| # Get weather details by city name: api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key} | ||||||||||||||||||||||||||||||||||||
| # There are many other things, treat those like your homework | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Get the time from utc and timezone values provided | ||||||||||||||||||||||||||||||||||||
| # pass the value as utc + timezone (both are UTC timestamp) | ||||||||||||||||||||||||||||||||||||
| def time_from_utc_with_timezone(utc_with_tz): | ||||||||||||||||||||||||||||||||||||
| local_time = datetime.utcfromtimestamp(utc_with_tz) | ||||||||||||||||||||||||||||||||||||
| return local_time.time() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # API url | ||||||||||||||||||||||||||||||||||||
| weather_url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city_name + '&appid='+api_key | ||||||||||||||||||||||||||||||||||||
|
|
@@ -31,35 +27,29 @@ def time_from_utc_with_timezone(utc_with_tz): | |||||||||||||||||||||||||||||||||||
| # response will be in json format and we need to change it to pythonic format | ||||||||||||||||||||||||||||||||||||
| weather_data = response.json() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Make sure you get 200 as response to proceed | ||||||||||||||||||||||||||||||||||||
| # SAMPLE DATA: {'coord': {'lon': 78.4744, 'lat': 17.3753}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], | ||||||||||||||||||||||||||||||||||||
| # 'base': 'stations', 'main': {'temp': 293.04, 'feels_like': 293.44, 'temp_min': 291.15, 'temp_max': 294.82, 'pressure': 1015, 'humidity': 72}, | ||||||||||||||||||||||||||||||||||||
| # 'visibility': 6000, 'wind': {'speed': 1.58, 'deg': 163}, 'clouds': {'all': 0}, 'dt': 1614196800, 'sys': {'type': 1, 'id': 9213, 'country': 'IN', | ||||||||||||||||||||||||||||||||||||
| # 'sunrise': 1614215239, 'sunset': 1614257484}, 'timezone': 19800, 'id': 1269843, 'name': 'Hyderabad', 'cod': 200} | ||||||||||||||||||||||||||||||||||||
| # weather_data['cod'] == '404' means city not found | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if weather_data['cod'] == 200: | ||||||||||||||||||||||||||||||||||||
| kelvin = 273.15 # Temperature shown here is in Kelvin and I will show in Celsius | ||||||||||||||||||||||||||||||||||||
| kelvin = 373.15 # Temperature shown here is in Kelvin and I will show in Celsius | ||||||||||||||||||||||||||||||||||||
| temp = int(weather_data['main']['temp'] - kelvin) | ||||||||||||||||||||||||||||||||||||
| feels_like_temp = int(weather_data['main']['feels_like'] - kelvin) | ||||||||||||||||||||||||||||||||||||
| pressure = weather_data['main']['pressure'] | ||||||||||||||||||||||||||||||||||||
| humidity = weather_data['main']['humidity'] | ||||||||||||||||||||||||||||||||||||
| wind_speed = weather_data['wind']['speed'] * 3.6 | ||||||||||||||||||||||||||||||||||||
| sunrise = weather_data['sys']['sunrise'] | ||||||||||||||||||||||||||||||||||||
| sunset = weather_data['sys']['sunset'] | ||||||||||||||||||||||||||||||||||||
| timezone = weather_data['timezone'] | ||||||||||||||||||||||||||||||||||||
| cloudy = weather_data['clouds']['all'] | ||||||||||||||||||||||||||||||||||||
| description = weather_data['weather'][0]['description'] | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| sunrise_time = time_from_utc_with_timezone(sunrise + timezone) | ||||||||||||||||||||||||||||||||||||
| sunset_time = time_from_utc_with_timezone(sunset + timezone) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| print(f"Weather Information for City: {city_name}") | ||||||||||||||||||||||||||||||||||||
| print(f"Temperature (Celsius): {temp}") | ||||||||||||||||||||||||||||||||||||
| print(f"Feels like in (Celsius): {feels_like_temp}") | ||||||||||||||||||||||||||||||||||||
| print(f"Pressure: {pressure} hPa") | ||||||||||||||||||||||||||||||||||||
| print(f"Humidity: {humidity}%") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| description = weather_data['weather'][0]['description'] | ||||||||||||||||||||||||||||||||||||
| sunrise_time = time_from_utc_with_timezone(sunrise + timezone) | ||||||||||||||||||||||||||||||||||||
| sunset_time = time_from_utc_with_timezone(sunset + timezone) | ||||||||||||||||||||||||||||||||||||
| print("Wind speed: {0:.2f} km/hr".format(wind_speed)) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| sunrise = weather_data['sys']['sunrise'] | ||||||||||||||||||||||||||||||||||||
| sunset = weather_data['sys']['sunset'] | ||||||||||||||||||||||||||||||||||||
| timezone = weather_data['timezone'] | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables used before definition
Variables Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||||||||||||||||
| cloudy = weather_data['clouds']['all'] | ||||||||||||||||||||||||||||||||||||
| print(f"Sunrise at {sunrise_time} and Sunset at {sunset_time}") | ||||||||||||||||||||||||||||||||||||
| print(f"Cloud: {cloudy}%") | ||||||||||||||||||||||||||||||||||||
| print(f"Info: {description}") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,13 +3,14 @@ | |||||
|
|
||||||
| from datetime import datetime | ||||||
|
|
||||||
| # Thanks to stackoverflow for this snippet | ||||||
| def time_from_utc_with_timezone(utc): | ||||||
| utc_time = datetime.utcfromtimestamp(utc) | ||||||
| return utc_time.time() | ||||||
|
|
||||||
| utc = 1614215239 | ||||||
| timezone = 19800 | ||||||
|
|
||||||
| utc_with_tz = utc + timezone | ||||||
| print(time_from_utc_with_timezone(utc_with_tz)) | ||||||
| print(_time_from_utc_with_timezone(utc_with_tz)) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undefined function name with underscore prefix
Function Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||
|
|
||||||
|
|
||||||
| # Thanks to stackoverflow for this snippet | ||||||
| def time_from_utc_with_timezone(utc): | ||||||
| utc_time = datetime.utcfromtimestamp(utc) | ||||||
| return utc_time.time() | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,20 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/python | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def check_prime(num): | ||||||||||||||||||||||||||||||||||||||||||||||||
| if(num > 1): | ||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(2, int(num**0.5) + 1): | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (num % i) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print(num) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inverted prime detection logic
The Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary else after break statement
Unnecessary Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||
| lower = int(input('Enter start range: ')) | ||||||||||||||||||||||||||||||||||||||||||||||||
| upper = int(input('Enter end range: ')) | ||||||||||||||||||||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bare except clause should specify exception
Do not use bare Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||||||||||||||||||||||||||||
| exit("Make sure ranges are integers only") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if( lower < 0 or upper < 0 ): | ||||||||||||||||||||||||||||||||||||||||||||||||
| exit("Ranges must be positive numbers") | ||||||||||||||||||||||||||||||||||||||||||||||||
| if( lower > 0 or upper > 0 ): | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect negative number validation logic
The condition Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||||||||||||||||||||||||||||
| system.exit("Ranges must be positive numbers") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undefined name system used
Name Code suggestionCheck the AI-generated fix before applying Code Review Run #830692 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| print("Prime numbers between", lower, "and", upper, "are:") | ||||||||||||||||||||||||||||||||||||||||||||||||
| for num in range(lower, upper+1): | ||||||||||||||||||||||||||||||||||||||||||||||||
| if(num > 1): | ||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(2, num): | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (num % i) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print(num) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
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 Kelvin to Celsius conversion constant is incorrect. Using
373.15instead of273.15will produce completely wrong temperature values. For example, a temperature of 20°C (293.15K) would show as -80°C instead of 20°C. Please change tokelvin = 273.15.Code suggestion
Code Review Run #830692
Should Bito avoid suggestions like this for future reviews? (Manage Rules)