Support city name as CLI parameter and add WeatherSkill module#3
Merged
Support city name as CLI parameter and add WeatherSkill module#3
Conversation
Co-authored-by: whitejoce <36195824+whitejoce@users.noreply.github.com>
Co-authored-by: whitejoce <36195824+whitejoce@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for passing city name to get weather results
Support city name as CLI parameter and add WeatherSkill module
Mar 14, 2026
whitejoce
approved these changes
Mar 14, 2026
whitejoce
approved these changes
Mar 14, 2026
whitejoce
reviewed
Mar 14, 2026
Owner
whitejoce
left a comment
There was a problem hiding this comment.
提供中英双版的SKILLS,参考:https://www.runoob.com/ai-agent/skills-agent.html
There was a problem hiding this comment.
Pull request overview
This PR changes the --city CLI parameter from accepting a raw numeric city code to accepting a human-readable city name (e.g., 北京), and introduces a new WeatherSkill.py module that wraps the weather querying logic into a clean, importable API.
Changes:
GetWeather.py:--citynow accepts a city name resolved viaget_city_code(), andmain_weather_process()gains acity_nameparameter to skip IP-based auto-detectionWeatherSkill.py(new): Providesquery_weather()andquery_weather_auto()functions as a reusable module with error handling via return values instead ofsys.exit().gitignore(new): Ignores__pycache__/,*.pyc,*.pyo,response.html, anddebug_results.json
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| GetWeather.py | Refactored --city to accept city names; added city_name parameter to main_weather_process(); debug mode resolves city name to code |
| WeatherSkill.py | New module wrapping weather queries with clean return-value-based API and CLI support |
| .gitignore | New file ignoring Python bytecode and generated output files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+31
to
+36
| try: | ||
| code = get_city_code(city_name) | ||
| weather_text = get_weather(code) | ||
| return weather_text | ||
| except SystemExit: | ||
| return f" [!] 未能找到城市 '{city_name}' 的天气信息" |
Comment on lines
+48
to
+55
| try: | ||
| address, code = get_CityName() | ||
| if not address: | ||
| return " [!] 无法自动定位城市,请使用 query_weather(city_name) 指定城市" | ||
| weather_text = get_weather(code) | ||
| return weather_text | ||
| except SystemExit: | ||
| return " [!] 未能获取当前位置的天气信息" |
Comment on lines
+294
to
+295
| print(f" [!] Debug 模式:未能找到城市 '{args.city}' 的城市代码,退出") | ||
| sys.exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--citypreviously accepted only a raw numeric city code; there was no importable interface for weather queries. This PR changes--cityto accept a human-readable city name and addsWeatherSkill.pyas a reusable skill module.GetWeather.py--citynow takes a city name (e.g.北京) and resolves it to a code viaget_city_code()internallymain_weather_process()gainscity_name=None; when set, skips IP-based auto-detection entirely--debugmode similarly resolves city name → code with an explicit error on lookup failureWeatherSkill.py(new)query_weather(city_name: str) -> str— named-city lookup, returns weather text, nosys.exitside-effectsquery_weather_auto() -> str— IP-based auto-detection variantMisc
.gitignorecovering__pycache__/,*.pyc,response.html,debug_results.jsonOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.