hkopenai.hk-climate-mcp-server 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 neo@01man.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: hkopenai.hk_climate_mcp_server
3
+ Version: 0.1.7
4
+ Summary: Hong Kong Weather MCP Server providing climate and weather data tools
5
+ Author-email: Neo Chow <neo@01man.com>
6
+ License-Expression: MIT
7
+ Project-URL: repository, https://github.com/hkopenai/hk-climate-mcp-server.git
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: fastmcp>=0.1.0
14
+ Requires-Dist: requests>=2.31.0
15
+ Requires-Dist: pytest>=8.2.0
16
+ Requires-Dist: pytest-cov>=6.1.1
17
+ Dynamic: license-file
18
+
19
+ # HKO MCP Server
20
+
21
+ [![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue.svg)](https://github.com/hkopenai/hk-climate-mcp-server)
22
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
23
+
24
+
25
+ This is an MCP server that provides access to climate and weather data through a FastMCP interface.
26
+
27
+ ## Data Source
28
+
29
+ * Hong Kong Observatory
30
+
31
+ ## Features
32
+ - Current weather: Get current weather observations from HKO (supports optional region parameter)
33
+
34
+ ## Setup
35
+
36
+ 1. Clone this repository
37
+ 2. Install Python dependencies:
38
+ ```bash
39
+ pip install -r requirements.txt
40
+ ```
41
+ 3. Run the server:
42
+ ```bash
43
+ python app.py
44
+ ```
45
+
46
+ ### Running Options
47
+
48
+ - Default stdio mode: `python app.py`
49
+ - SSE mode (port 8000): `python app.py --sse`
50
+
51
+ ## Cline Integration
52
+
53
+ To connect this MCP server to Cline using stdio:
54
+
55
+ 1. Add this configuration to your Cline MCP settings (cline_mcp_settings.json):
56
+ ```json
57
+ {
58
+ "hko-server": {
59
+ "disabled": false,
60
+ "timeout": 3,
61
+ "type": "stdio",
62
+ "command": "python",
63
+ "args": [
64
+ "c:/Projects/hkopenai/hk-climate-mcp-server/app.py"
65
+ ]
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Testing
71
+
72
+ Tests are available in `tests`. Run with:
73
+ ```bash
74
+ pytest
@@ -0,0 +1,56 @@
1
+ # HKO MCP Server
2
+
3
+ [![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue.svg)](https://github.com/hkopenai/hk-climate-mcp-server)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+
7
+ This is an MCP server that provides access to climate and weather data through a FastMCP interface.
8
+
9
+ ## Data Source
10
+
11
+ * Hong Kong Observatory
12
+
13
+ ## Features
14
+ - Current weather: Get current weather observations from HKO (supports optional region parameter)
15
+
16
+ ## Setup
17
+
18
+ 1. Clone this repository
19
+ 2. Install Python dependencies:
20
+ ```bash
21
+ pip install -r requirements.txt
22
+ ```
23
+ 3. Run the server:
24
+ ```bash
25
+ python app.py
26
+ ```
27
+
28
+ ### Running Options
29
+
30
+ - Default stdio mode: `python app.py`
31
+ - SSE mode (port 8000): `python app.py --sse`
32
+
33
+ ## Cline Integration
34
+
35
+ To connect this MCP server to Cline using stdio:
36
+
37
+ 1. Add this configuration to your Cline MCP settings (cline_mcp_settings.json):
38
+ ```json
39
+ {
40
+ "hko-server": {
41
+ "disabled": false,
42
+ "timeout": 3,
43
+ "type": "stdio",
44
+ "command": "python",
45
+ "args": [
46
+ "c:/Projects/hkopenai/hk-climate-mcp-server/app.py"
47
+ ]
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Testing
53
+
54
+ Tests are available in `tests`. Run with:
55
+ ```bash
56
+ pytest
@@ -0,0 +1,6 @@
1
+ """Hong Kong climate MCP Server package."""
2
+ from .app import main
3
+ from .tool_weather import get_current_weather
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ['main', 'get_current_weather']
@@ -0,0 +1,4 @@
1
+ from hkopenai.hk_climate_mcp_server.app import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,35 @@
1
+ import argparse
2
+ from fastmcp import FastMCP
3
+ from hkopenai.hk_climate_mcp_server import tool_weather
4
+ from typing import Dict, Annotated, Optional
5
+ from pydantic import Field
6
+
7
+ def create_mcp_server():
8
+ """Create and configure the HKO MCP server"""
9
+ mcp = FastMCP(name="HKOServer")
10
+
11
+ @mcp.tool(
12
+ description="Get current weather observations, warnings, temperature, humidity and rainfall in Hong Kong from Hong Kong Observatory, with optional region or place in Hong Kong",
13
+ )
14
+ def get_current_weather(region: str = "Hong Kong Observatory") -> Dict:
15
+ return tool_weather.get_current_weather(region)
16
+
17
+ return mcp
18
+
19
+ def main():
20
+ parser = argparse.ArgumentParser(description='HKO MCP Server')
21
+ parser.add_argument('-s', '--sse', action='store_true',
22
+ help='Run in SSE mode instead of stdio')
23
+ args = parser.parse_args()
24
+
25
+ server = create_mcp_server()
26
+
27
+ if args.sse:
28
+ server.run(transport="streamable-http")
29
+ print("HKO MCP Server running in SSE mode on port 8000")
30
+ else:
31
+ server.run()
32
+ print("HKO MCP Server running in stdio mode")
33
+
34
+ if __name__ == "__main__":
35
+ main()
@@ -0,0 +1,88 @@
1
+ import requests
2
+ from typing import Dict
3
+
4
+ def get_current_weather(region: str = "Hong Kong Observatory") -> Dict:
5
+ """
6
+ Get current weather observations for a specific region in Hong Kong
7
+
8
+ Args:
9
+ region: The region to get weather for (default: "Hong Kong Observatory")
10
+
11
+ Returns:
12
+ Dict containing:
13
+ - warning: Current weather warnings
14
+ - temperature: Current temperature in Celsius
15
+ - humidity: Current humidity percentage
16
+ - rainfall: Current rainfall in mm
17
+ """
18
+ response = requests.get(
19
+ "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread"
20
+ )
21
+ data = response.json()
22
+
23
+ # Handle warnings
24
+ warning = "No warning in force"
25
+ if "warningMessage" in data and data["warningMessage"]:
26
+ warning = data["warningMessage"][0]
27
+
28
+ # Get default values from HKO data
29
+ default_temp = next(
30
+ (
31
+ t
32
+ for t in data.get("temperature", {}).get("data", [])
33
+ if t.get("place") == "Hong Kong Observatory"
34
+ ),
35
+ {"value": 25, "unit": "C", "recordTime": ""},
36
+ )
37
+ default_humidity = next(
38
+ (
39
+ h
40
+ for h in data.get("humidity", {}).get("data", [])
41
+ if h.get("place") == "Hong Kong Observatory"
42
+ ),
43
+ {"value": 60, "unit": "percent", "recordTime": ""},
44
+ )
45
+ # Find matching region temperature
46
+ temp_data = data.get("temperature", {}).get("data", [])
47
+ matched_temp = next(
48
+ (t for t in temp_data if t["place"].lower() == region.lower()),
49
+ {
50
+ "place": "Hong Kong Observatory",
51
+ "value": default_temp["value"],
52
+ "unit": default_temp["unit"],
53
+ },
54
+ )
55
+ matched_temp["recordTime"] = data["temperature"]["recordTime"]
56
+
57
+ # Get humidity
58
+ humidity = next(
59
+ (
60
+ h
61
+ for h in data.get("humidity", {}).get("data", [])
62
+ if h.get("place") == matched_temp["place"]
63
+ ),
64
+ default_humidity,
65
+ )
66
+ humidity["recordTime"] = data["humidity"]["recordTime"]
67
+
68
+ # Get rainfall (0 if no rain)
69
+ rainfall = 0
70
+ if "rainfall" in data:
71
+ rainfall = max(float(r.get("max", 0)) for r in data["rainfall"]["data"])
72
+ rainfall_start = data["rainfall"]["startTime"]
73
+ rainfall_end = data["rainfall"]["endTime"]
74
+
75
+ return {
76
+ "warning": warning,
77
+ "temperature": {
78
+ "value": matched_temp["value"],
79
+ "unit": matched_temp["unit"],
80
+ "recordTime": matched_temp["recordTime"],
81
+ },
82
+ "humidity": {
83
+ "value": humidity["value"],
84
+ "unit": humidity["unit"],
85
+ "recordTime": humidity["recordTime"],
86
+ },
87
+ "rainfall": {"value": rainfall, "startTime": rainfall_start, "endTime": rainfall_end},
88
+ }
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: hkopenai.hk_climate_mcp_server
3
+ Version: 0.1.7
4
+ Summary: Hong Kong Weather MCP Server providing climate and weather data tools
5
+ Author-email: Neo Chow <neo@01man.com>
6
+ License-Expression: MIT
7
+ Project-URL: repository, https://github.com/hkopenai/hk-climate-mcp-server.git
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: fastmcp>=0.1.0
14
+ Requires-Dist: requests>=2.31.0
15
+ Requires-Dist: pytest>=8.2.0
16
+ Requires-Dist: pytest-cov>=6.1.1
17
+ Dynamic: license-file
18
+
19
+ # HKO MCP Server
20
+
21
+ [![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue.svg)](https://github.com/hkopenai/hk-climate-mcp-server)
22
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
23
+
24
+
25
+ This is an MCP server that provides access to climate and weather data through a FastMCP interface.
26
+
27
+ ## Data Source
28
+
29
+ * Hong Kong Observatory
30
+
31
+ ## Features
32
+ - Current weather: Get current weather observations from HKO (supports optional region parameter)
33
+
34
+ ## Setup
35
+
36
+ 1. Clone this repository
37
+ 2. Install Python dependencies:
38
+ ```bash
39
+ pip install -r requirements.txt
40
+ ```
41
+ 3. Run the server:
42
+ ```bash
43
+ python app.py
44
+ ```
45
+
46
+ ### Running Options
47
+
48
+ - Default stdio mode: `python app.py`
49
+ - SSE mode (port 8000): `python app.py --sse`
50
+
51
+ ## Cline Integration
52
+
53
+ To connect this MCP server to Cline using stdio:
54
+
55
+ 1. Add this configuration to your Cline MCP settings (cline_mcp_settings.json):
56
+ ```json
57
+ {
58
+ "hko-server": {
59
+ "disabled": false,
60
+ "timeout": 3,
61
+ "type": "stdio",
62
+ "command": "python",
63
+ "args": [
64
+ "c:/Projects/hkopenai/hk-climate-mcp-server/app.py"
65
+ ]
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Testing
71
+
72
+ Tests are available in `tests`. Run with:
73
+ ```bash
74
+ pytest
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ hkopenai.hk_climate_mcp_server.egg-info/PKG-INFO
5
+ hkopenai.hk_climate_mcp_server.egg-info/SOURCES.txt
6
+ hkopenai.hk_climate_mcp_server.egg-info/dependency_links.txt
7
+ hkopenai.hk_climate_mcp_server.egg-info/entry_points.txt
8
+ hkopenai.hk_climate_mcp_server.egg-info/requires.txt
9
+ hkopenai.hk_climate_mcp_server.egg-info/top_level.txt
10
+ hkopenai/hk_climate_mcp_server/__init__.py
11
+ hkopenai/hk_climate_mcp_server/__main__.py
12
+ hkopenai/hk_climate_mcp_server/app.py
13
+ hkopenai/hk_climate_mcp_server/tool_weather.py
14
+ tests/test_app.py
15
+ tests/test_tools.py
16
+ tests/test_weather.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ hk_climate_mcp_server = hkopenai.hk_climate_mcp_server.app:main
@@ -0,0 +1,4 @@
1
+ fastmcp>=0.1.0
2
+ requests>=2.31.0
3
+ pytest>=8.2.0
4
+ pytest-cov>=6.1.1
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools]
6
+ packages = ["hkopenai.hk_climate_mcp_server"]
7
+ include-package-data = false
8
+
9
+ [tool.hatch.build.targets.wheel]
10
+ packages = ["hkopenai"]
11
+
12
+ [tool.bandit]
13
+ exclude_dirs = ["venv", ".venv", "tests"]
14
+
15
+ [project.urls]
16
+ repository = "https://github.com/hkopenai/hk-climate-mcp-server.git"
17
+
18
+ [project]
19
+ name = "hkopenai.hk_climate_mcp_server"
20
+ version = "0.1.7"
21
+ description = "Hong Kong Weather MCP Server providing climate and weather data tools"
22
+ readme = "README.md"
23
+ requires-python = ">=3.7"
24
+ authors = [
25
+ {name = "Neo Chow", email = "neo@01man.com"}
26
+ ]
27
+ license = "MIT"
28
+ classifiers = [
29
+ "Programming Language :: Python :: 3",
30
+ "Operating System :: OS Independent",
31
+ ]
32
+ dependencies = [
33
+ "fastmcp>=0.1.0",
34
+ "requests>=2.31.0",
35
+ "pytest>=8.2.0",
36
+ "pytest-cov>=6.1.1"
37
+ ]
38
+
39
+ [project.scripts]
40
+ hk_climate_mcp_server = "hkopenai.hk_climate_mcp_server.app:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,48 @@
1
+ import unittest
2
+ from unittest.mock import patch, Mock
3
+ from hkopenai.hk_climate_mcp_server.app import create_mcp_server
4
+
5
+ class TestApp(unittest.TestCase):
6
+ @patch('hkopenai.hk_climate_mcp_server.app.FastMCP')
7
+ @patch('hkopenai.hk_climate_mcp_server.app.tool_weather')
8
+ def test_create_mcp_server(self, mock_tool_weather, mock_fastmcp):
9
+ # Setup mocks
10
+ mock_server = unittest.mock.Mock()
11
+
12
+ # Track decorator calls and capture decorated function
13
+ decorator_calls = []
14
+ decorated_func = None
15
+
16
+ def tool_decorator(description=None):
17
+ # First call: @tool(description=...)
18
+ decorator_calls.append(((), {'description': description}))
19
+
20
+ def decorator(f):
21
+ # Second call: decorator(function)
22
+ nonlocal decorated_func
23
+ decorated_func = f
24
+ return f
25
+
26
+ return decorator
27
+
28
+ mock_server.tool = tool_decorator
29
+ mock_server.tool.call_args = None # Initialize call_args
30
+ mock_fastmcp.return_value = mock_server
31
+ mock_tool_weather.get_current_weather.return_value = {'test': 'data'}
32
+
33
+ # Test server creation
34
+ server = create_mcp_server()
35
+
36
+ # Verify server creation
37
+ mock_fastmcp.assert_called_once()
38
+ self.assertEqual(server, mock_server)
39
+
40
+ # Verify tool was decorated
41
+ self.assertIsNotNone(decorated_func)
42
+
43
+ # Test the actual decorated function
44
+ result = decorated_func(region="test")
45
+ mock_tool_weather.get_current_weather.assert_called_once_with("test")
46
+
47
+ if __name__ == "__main__":
48
+ unittest.main()
@@ -0,0 +1,15 @@
1
+ import unittest
2
+ from tests.test_weather import TestWeatherTools
3
+ from tests.test_app import TestApp
4
+
5
+ def suite():
6
+ loader = unittest.TestLoader()
7
+ suite = unittest.TestSuite()
8
+ suite.addTests(loader.loadTestsFromTestCase(TestWeatherTools))
9
+ suite.addTests(loader.loadTestsFromTestCase(TestApp))
10
+ return suite
11
+
12
+ if __name__ == '__main__':
13
+ runner = unittest.TextTestRunner(verbosity=2)
14
+ test_suite = suite()
15
+ runner.run(test_suite)
@@ -0,0 +1,155 @@
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ from hkopenai.hk_climate_mcp_server import get_current_weather
4
+
5
+ class TestWeatherTools(unittest.TestCase):
6
+ default_mock_response = {
7
+ "rainfall": {
8
+ "data": [
9
+ {
10
+ "unit": "mm",
11
+ "place": "Central & Western District",
12
+ "max": 0,
13
+ "main": "FALSE",
14
+ },
15
+ {
16
+ "unit": "mm",
17
+ "place": "Eastern District",
18
+ "max": 0,
19
+ "main": "FALSE",
20
+ },
21
+ {"unit": "mm", "place": "Kwai Tsing", "max": 0, "main": "FALSE"},
22
+ {
23
+ "unit": "mm",
24
+ "place": "Islands District",
25
+ "max": 0,
26
+ "main": "FALSE",
27
+ },
28
+ {
29
+ "unit": "mm",
30
+ "place": "North District",
31
+ "max": 0,
32
+ "main": "FALSE",
33
+ },
34
+ {"unit": "mm", "place": "Sai Kung", "max": 0, "main": "FALSE"},
35
+ {"unit": "mm", "place": "Sha Tin", "max": 0, "main": "FALSE"},
36
+ {
37
+ "unit": "mm",
38
+ "place": "Southern District",
39
+ "max": 0,
40
+ "main": "FALSE",
41
+ },
42
+ {"unit": "mm", "place": "Tai Po", "max": 0, "main": "FALSE"},
43
+ {"unit": "mm", "place": "Tsuen Wan", "max": 0, "main": "FALSE"},
44
+ {"unit": "mm", "place": "Tuen Mun", "max": 0, "main": "FALSE"},
45
+ {"unit": "mm", "place": "Wan Chai", "max": 0, "main": "FALSE"},
46
+ {"unit": "mm", "place": "Yuen Long", "max": 0, "main": "FALSE"},
47
+ {"unit": "mm", "place": "Yau Tsim Mong", "max": 0, "main": "FALSE"},
48
+ {"unit": "mm", "place": "Sham Shui Po", "max": 0, "main": "FALSE"},
49
+ {"unit": "mm", "place": "Kowloon City", "max": 0, "main": "FALSE"},
50
+ {"unit": "mm", "place": "Wong Tai Sin", "max": 0, "main": "FALSE"},
51
+ {"unit": "mm", "place": "Kwun Tong", "max": 0, "main": "FALSE"},
52
+ ],
53
+ "startTime": "2025-06-07T20:45:00+08:00",
54
+ "endTime": "2025-06-07T21:45:00+08:00",
55
+ },
56
+ "icon": [72],
57
+ "iconUpdateTime": "2025-06-07T18:00:00+08:00",
58
+ "uvindex": "",
59
+ "updateTime": "2025-06-07T22:02:00+08:00",
60
+ "temperature": {
61
+ "data": [
62
+ {"place": "King's Park", "value": 28, "unit": "C"},
63
+ {"place": "Hong Kong Observatory", "value": 29, "unit": "C"},
64
+ {"place": "Wong Chuk Hang", "value": 28, "unit": "C"},
65
+ {"place": "Ta Kwu Ling", "value": 28, "unit": "C"},
66
+ {"place": "Lau Fau Shan", "value": 28, "unit": "C"},
67
+ {"place": "Tai Po", "value": 29, "unit": "C"},
68
+ {"place": "Sha Tin", "value": 29, "unit": "C"},
69
+ {"place": "Tuen Mun", "value": 29, "unit": "C"},
70
+ {"place": "Tseung Kwan O", "value": 27, "unit": "C"},
71
+ {"place": "Sai Kung", "value": 28, "unit": "C"},
72
+ {"place": "Cheung Chau", "value": 27, "unit": "C"},
73
+ {"place": "Chek Lap Kok", "value": 29, "unit": "C"},
74
+ {"place": "Tsing Yi", "value": 28, "unit": "C"},
75
+ {"place": "Shek Kong", "value": 29, "unit": "C"},
76
+ {"place": "Tsuen Wan Ho Koon", "value": 27, "unit": "C"},
77
+ {"place": "Tsuen Wan Shing Mun Valley", "value": 28, "unit": "C"},
78
+ {"place": "Hong Kong Park", "value": 28, "unit": "C"},
79
+ {"place": "Shau Kei Wan", "value": 28, "unit": "C"},
80
+ {"place": "Kowloon City", "value": 29, "unit": "C"},
81
+ {"place": "Happy Valley", "value": 29, "unit": "C"},
82
+ {"place": "Wong Tai Sin", "value": 29, "unit": "C"},
83
+ {"place": "Stanley", "value": 28, "unit": "C"},
84
+ {"place": "Kwun Tong", "value": 28, "unit": "C"},
85
+ {"place": "Sham Shui Po", "value": 29, "unit": "C"},
86
+ {"place": "Kai Tak Runway Park", "value": 29, "unit": "C"},
87
+ {"place": "Yuen Long Park", "value": 28, "unit": "C"},
88
+ {"place": "Tai Mei Tuk", "value": 28, "unit": "C"},
89
+ ],
90
+ "recordTime": "2025-06-07T22:00:00+08:00",
91
+ },
92
+ "warningMessage": [
93
+ "The Very Hot weather Warning is now in force. Prolonged heat alert! Please drink sufficient water. If feeling unwell, take rest or seek help immediately. If needed, seek medical advice as soon as possible."
94
+ ],
95
+ "mintempFrom00To09": "",
96
+ "rainfallFrom00To12": "",
97
+ "rainfallLastMonth": "",
98
+ "rainfallJanuaryToLastMonth": "",
99
+ "tcmessage": "",
100
+ "humidity": {
101
+ "recordTime": "2025-06-07T22:00:00+08:00",
102
+ "data": [
103
+ {"unit": "percent", "value": 79, "place": "Hong Kong Observatory"}
104
+ ],
105
+ },
106
+ }
107
+
108
+ @patch("requests.get")
109
+ def test_get_current_weather(self, mock_get):
110
+ # Setup mock response
111
+ mock_response = MagicMock()
112
+ mock_response.json.return_value = self.default_mock_response
113
+ mock_get.return_value = mock_response
114
+
115
+ # Test
116
+ result = get_current_weather()
117
+ self.assertEqual(result['temperature']['value'], 29)
118
+ self.assertEqual(result['temperature']['unit'], "C")
119
+ self.assertEqual(result['temperature']['recordTime'], "2025-06-07T22:00:00+08:00",)
120
+ self.assertEqual(result['humidity']['value'], 79)
121
+ self.assertEqual(result['humidity']['unit'], "percent")
122
+ self.assertEqual(result['humidity']['recordTime'], "2025-06-07T22:00:00+08:00",)
123
+ self.assertEqual(result['rainfall']['value'], 0)
124
+ self.assertEqual(result['rainfall']['startTime'], "2025-06-07T20:45:00+08:00")
125
+ self.assertEqual(result['rainfall']['endTime'], "2025-06-07T21:45:00+08:00")
126
+ self.assertEqual(result['warning'], 'The Very Hot weather Warning is now in force. Prolonged heat alert! Please drink sufficient water. If feeling unwell, take rest or seek help immediately. If needed, seek medical advice as soon as possible.')
127
+ mock_get.assert_called_once_with(
128
+ "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread"
129
+ )
130
+
131
+ @patch("requests.get")
132
+ def test_get_current_weather_with_region(self, mock_get):
133
+ # Setup mock response
134
+ mock_response = MagicMock()
135
+ mock_response.json.return_value = self.default_mock_response
136
+ mock_get.return_value = mock_response
137
+
138
+ # Test
139
+ result = get_current_weather("Cheung Chau")
140
+ self.assertEqual(result['temperature']['value'], 27)
141
+ self.assertEqual(result['temperature']['unit'], "C")
142
+ self.assertEqual(result['temperature']['recordTime'], "2025-06-07T22:00:00+08:00",)
143
+ self.assertEqual(result['humidity']['value'], 79)
144
+ self.assertEqual(result['humidity']['unit'], "percent")
145
+ self.assertEqual(result['humidity']['recordTime'], "2025-06-07T22:00:00+08:00",)
146
+ self.assertEqual(result['rainfall']['value'], 0)
147
+ self.assertEqual(result['rainfall']['startTime'], "2025-06-07T20:45:00+08:00")
148
+ self.assertEqual(result['rainfall']['endTime'], "2025-06-07T21:45:00+08:00")
149
+ self.assertEqual(result['warning'], 'The Very Hot weather Warning is now in force. Prolonged heat alert! Please drink sufficient water. If feeling unwell, take rest or seek help immediately. If needed, seek medical advice as soon as possible.')
150
+ mock_get.assert_called_once_with(
151
+ "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread"
152
+ )
153
+
154
+ if __name__ == "__main__":
155
+ unittest.main()