Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"customizations": {
"codespaces": {
"openFiles": [
"README.md",
"weather_api.py"
]
},
"vscode": {
"settings": {},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
}
},
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'",
"postAttachCommand": {
"server": "streamlit run weather_api.py --server.enableCORS false --server.enableXsrfProtection false"
},
"portsAttributes": {
"8501": {
"label": "Application",
"onAutoForward": "openPreview"
}
},
"forwardPorts": [
8501
]
}
1 change: 1 addition & 0 deletions hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello world")
21 changes: 21 additions & 0 deletions streamlit_test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import streamlit as st
# Initialize session state for storing past inputs
if 'text_history' not in st.session_state:
st.session_state.text_history = []
# Create a text input box
text_input = st.text_input("Enter some text:")
# Create a submit button
submit_button = st.button("Submit")
if submit_button:
st.session_state.text_history.append(text_input)
st.write("You've inputted:", text_input)
st.session_state.input_box = ""
# Clear the input box
# Create a clear button
clear_button = st.button("Clear History")
if clear_button:
st.session_state.text_history = []
# Display the list of past submitted input
st.write("## Past inputs")
for text in st.session_state.text_history:
st.write(text)
290 changes: 290 additions & 0 deletions weather.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{
"rainfall": {
"data": [
{
"unit": "mm",
"place": "Central & Western District",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Eastern District",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Kwai Tsing",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Islands District",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "North District",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Sai Kung",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Sha Tin",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Southern District",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Tai Po",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Tsuen Wan",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Tuen Mun",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Wan Chai",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Yuen Long",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Yau Tsim Mong",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Sham Shui Po",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Kowloon City",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Wong Tai Sin",
"max": 0,
"main": "FALSE"
},
{
"unit": "mm",
"place": "Kwun Tong",
"max": 0,
"main": "FALSE"
}
],
"startTime": "2024-09-12T13:45:00+08:00",
"endTime": "2024-09-12T14:45:00+08:00"
},
"icon": [
53
],
"iconUpdateTime": "2024-09-12T14:58:00+08:00",
"uvindex": {
"data": [
{
"place": "King's Park",
"value": 6,
"desc": "high"
}
],
"recordDesc": "During the past hour"
},
"updateTime": "2024-09-12T15:02:00+08:00",
"temperature": {
"data": [
{
"place": "King's Park",
"value": 32,
"unit": "C"
},
{
"place": "Hong Kong Observatory",
"value": 32,
"unit": "C"
},
{
"place": "Wong Chuk Hang",
"value": 32,
"unit": "C"
},
{
"place": "Ta Kwu Ling",
"value": 31,
"unit": "C"
},
{
"place": "Lau Fau Shan",
"value": 29,
"unit": "C"
},
{
"place": "Tai Po",
"value": 31,
"unit": "C"
},
{
"place": "Sha Tin",
"value": 32,
"unit": "C"
},
{
"place": "Tuen Mun",
"value": 32,
"unit": "C"
},
{
"place": "Tseung Kwan O",
"value": 33,
"unit": "C"
},
{
"place": "Sai Kung",
"value": 31,
"unit": "C"
},
{
"place": "Cheung Chau",
"value": 33,
"unit": "C"
},
{
"place": "Chek Lap Kok",
"value": 32,
"unit": "C"
},
{
"place": "Tsing Yi",
"value": 31,
"unit": "C"
},
{
"place": "Shek Kong",
"value": 31,
"unit": "C"
},
{
"place": "Tsuen Wan Ho Koon",
"value": 30,
"unit": "C"
},
{
"place": "Tsuen Wan Shing Mun Valley",
"value": 32,
"unit": "C"
},
{
"place": "Hong Kong Park",
"value": 31,
"unit": "C"
},
{
"place": "Shau Kei Wan",
"value": 32,
"unit": "C"
},
{
"place": "Kowloon City",
"value": 33,
"unit": "C"
},
{
"place": "Happy Valley",
"value": 33,
"unit": "C"
},
{
"place": "Wong Tai Sin",
"value": 33,
"unit": "C"
},
{
"place": "Stanley",
"value": 31,
"unit": "C"
},
{
"place": "Kwun Tong",
"value": 33,
"unit": "C"
},
{
"place": "Sham Shui Po",
"value": 32,
"unit": "C"
},
{
"place": "Kai Tak Runway Park",
"value": 33,
"unit": "C"
},
{
"place": "Yuen Long Park",
"value": 33,
"unit": "C"
},
{
"place": "Tai Mei Tuk",
"value": 33,
"unit": "C"
}
],
"recordTime": "2024-09-12T15:00:00+08:00"
},
"warningMessage": [
"The Thunderstorm Warning was issued at 2:58 p.m. It will remain effective until 4:15 p.m. today. Isolated thunderstorms are expected to occur over New Territories.",
"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."
],
"mintempFrom00To09": "",
"rainfallFrom00To12": "",
"rainfallLastMonth": "",
"rainfallJanuaryToLastMonth": "",
"tcmessage": "",
"humidity": {
"recordTime": "2024-09-12T15:00:00+08:00",
"data": [
{
"unit": "percent",
"value": 65,
"place": "Hong Kong Observatory"
}
]
}
}
15 changes: 15 additions & 0 deletions weather_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import requests
import json
# Make a GET request to the weather API
result = requests.get('https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang=en')
# Save the JSON response to a file
with open('weather.json', 'w') as f:
output_json = json.dumps(result.json(), indent=4, sort_keys=True)
f.write(output_json)

result_dict = json.loads(result.text) #parse the json string into a dict object

print(result.status_code)
print(result_dict["humidity"])
print(result_dict["humidity"]["data"][0])
print(result_dict["humidity"]["data"][0]["value"])