Skip to content

Support city name as CLI parameter and add WeatherSkill module#3

Merged
whitejoce merged 3 commits intomainfrom
copilot/add-city-parameter-support
Mar 14, 2026
Merged

Support city name as CLI parameter and add WeatherSkill module#3
whitejoce merged 3 commits intomainfrom
copilot/add-city-parameter-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

--city previously accepted only a raw numeric city code; there was no importable interface for weather queries. This PR changes --city to accept a human-readable city name and adds WeatherSkill.py as a reusable skill module.

GetWeather.py

  • --city now takes a city name (e.g. 北京) and resolves it to a code via get_city_code() internally
  • main_weather_process() gains city_name=None; when set, skips IP-based auto-detection entirely
  • --debug mode similarly resolves city name → code with an explicit error on lookup failure

WeatherSkill.py (new)

  • query_weather(city_name: str) -> str — named-city lookup, returns weather text, no sys.exit side-effects
  • query_weather_auto() -> str — IP-based auto-detection variant
  • Usable as an importable module or standalone CLI
# GetWeather.py — direct city name
python GetWeather.py --city 北京

# WeatherSkill.py — as a skill/module
from WeatherSkill import query_weather
print(query_weather("上海"))

# or as CLI
python WeatherSkill.py --city 广州

Misc

  • Added .gitignore covering __pycache__/, *.pyc, response.html, debug_results.json
Original prompt

查看仓库代码,修改为支持参数传递城市名称,输出天气结果,然后编写一个查询天气的Skill,使用这个脚本


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 14, 2026 08:37
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
Copilot AI requested a review from whitejoce March 14, 2026 08:38
@whitejoce whitejoce self-requested a review March 14, 2026 23:11
Copy link
Owner

@whitejoce whitejoce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Owner

@whitejoce whitejoce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copilot AI requested a review from whitejoce March 14, 2026 23:14
@whitejoce whitejoce requested review from Copilot and removed request for whitejoce March 14, 2026 23:16
Copy link
Owner

@whitejoce whitejoce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提供中英双版的SKILLS,参考:https://www.runoob.com/ai-agent/skills-agent.html

@whitejoce whitejoce marked this pull request as ready for review March 14, 2026 23:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: --city now accepts a city name resolved via get_city_code(), and main_weather_process() gains a city_name parameter to skip IP-based auto-detection
  • WeatherSkill.py (new): Provides query_weather() and query_weather_auto() functions as a reusable module with error handling via return values instead of sys.exit()
  • .gitignore (new): Ignores __pycache__/, *.pyc, *.pyo, response.html, and debug_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)
@whitejoce whitejoce merged commit 5c4b2c5 into main Mar 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants