Skip to content

Commit d04fdc7

Browse files
committed
TR updates, first round
1 parent b7c7687 commit d04fdc7

File tree

3 files changed

+48
-59
lines changed

3 files changed

+48
-59
lines changed

python-uv/main.py

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,56 @@
11
import argparse
2+
import sys
23

34
import requests
45

5-
WEATHER_EMOJIS = {
6-
"clear": "☀️",
7-
"sunny": "☀️",
8-
"cloudy": "☁️",
9-
"partly cloudy": "⛅",
10-
"rain": "🌧️",
11-
"light rain": "🌦️",
12-
"heavy rain": "🌊",
13-
"storm": "🌩️",
14-
"snow": "❄️",
15-
"fog": "🌫️",
16-
"mist": "🌫️",
17-
"default": "🌍",
18-
}
196

20-
API_QUERY_TEMPLATE = "https://wttr.in/{city}?format=%C+%t"
7+
def get_breeds_info():
8+
response = requests.get("https://api.thecatapi.com/v1/breeds")
9+
response.raise_for_status()
10+
return response.json()
2111

2212

23-
def get_weather_emoji(condition, weather_emojis=WEATHER_EMOJIS):
24-
condition = condition.lower()
25-
for key, emoji in weather_emojis.items():
26-
if key in condition:
27-
return emoji
28-
return weather_emojis["default"]
13+
def find_breed_info(breed_name):
14+
json_response = get_breeds_info()
15+
for breed in json_response:
16+
if breed["name"] == breed_name:
17+
return breed
18+
return {}
2919

3020

31-
def get_weather(city, api_query_template=API_QUERY_TEMPLATE):
32-
api_query = api_query_template.format(city=city)
33-
try:
34-
response = requests.get(api_query)
35-
response.raise_for_status()
36-
weather_info = response.text.strip().split("+")
37-
if len(weather_info) < 2:
38-
return "Error: Unexpected weather data format."
39-
condition = weather_info[0].strip()
40-
temperature = weather_info[1].strip()
41-
emoji = get_weather_emoji(condition)
42-
return f"{emoji} {condition} -> {temperature}"
43-
except requests.RequestException:
44-
return "Error: Could not retrieve weather data."
21+
def display_breed_profile(breed):
22+
print(f"\n{breed['name']:-^30s}")
23+
print(f"Origin: {breed['origin']}")
24+
print(f"Temperament: {breed['temperament']}")
25+
print(f"Life Span: {breed['life_span']} years")
26+
print(f"Weight: {breed['weight']['imperial']} lbs")
27+
if breed.get("wikipedia_url"):
28+
print(f"\nLearn more: {breed['wikipedia_url']}")
4529

4630

47-
def parse_cli_args():
48-
parser = argparse.ArgumentParser(
49-
prog="weather",
50-
description="Weather information for the specified city.",
51-
epilog="Thanks for using %(prog)s! :)",
52-
)
53-
parser.add_argument(
54-
"city",
55-
nargs="+",
56-
help="Name of the city to get weather information for",
57-
)
31+
def parse_args():
32+
parser = argparse.ArgumentParser(description="Get information about cat breeds")
5833
parser.add_argument(
59-
"--version",
60-
action="version",
61-
version="%(prog)s 0.1.0",
34+
"breed",
35+
help="Name of cat breed (e.g., 'Siamese')",
6236
)
6337
return parser.parse_args()
6438

6539

6640
def main():
67-
args = parse_cli_args()
68-
weather = get_weather(" ".join(args.city))
69-
print(weather)
41+
args = parse_args()
42+
try:
43+
breed = find_breed_info(args.breed)
44+
if not breed:
45+
print("Breed not found. Try another breed name.")
46+
return 0
47+
display_breed_profile(breed)
48+
except Exception as e:
49+
print(f"Error: {e}")
50+
return 1
51+
52+
return 0
7053

7154

7255
if __name__ == "__main__":
73-
main()
56+
sys.exit(main())

python-uv/pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
2-
name = "rpweather"
2+
name = "rpcats"
33
version = "0.1.0"
4-
description = "Display weather information for the specified city."
4+
description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.13"
77
dependencies = [
@@ -14,8 +14,14 @@ dev = [
1414
]
1515

1616
[project.scripts]
17-
rpweather = "main:main"
17+
rpcats = "main:main"
1818

1919
[build-system]
2020
requires = ["setuptools>=78.1.0", "wheel>=0.45.1"]
21-
build-backend = "setuptools.build_meta"
21+
build-backend = "setuptools.build_meta"
22+
23+
[[tool.uv.index]]
24+
name = "testpypi"
25+
url = "https://test.pypi.org/simple/"
26+
publish-url = "https://test.pypi.org/legacy/"
27+
explicit = true

python-uv/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)