From 3018fd3a0c706c94b02e51faf2f4a371dc4b5997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 02:58:39 +0000 Subject: [PATCH 1/6] add basic python code --- hello.py | 1 + streamlit_test1.py | 21 +++++++++++++++++++++ students.json | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 hello.py create mode 100644 streamlit_test1.py create mode 100644 students.json diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..e75154b --- /dev/null +++ b/hello.py @@ -0,0 +1 @@ +print("hello world") \ No newline at end of file diff --git a/streamlit_test1.py b/streamlit_test1.py new file mode 100644 index 0000000..23e299a --- /dev/null +++ b/streamlit_test1.py @@ -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) \ No newline at end of file diff --git a/students.json b/students.json new file mode 100644 index 0000000..4c430f1 --- /dev/null +++ b/students.json @@ -0,0 +1,22 @@ +{ + "students": [ + { + "id": 1, + "name": "Alice", + "age": 20, + "grades": { + "math": 90, + "science": 85 + } + }, + { + "id": 2, + "name": "Bob", + "age": 22, + "grades": { + "math": 75, + "science": 80 + } + } + ] +} From f81a646094e4d9c29ced4a683ceb99eb781a9cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 03:18:36 +0000 Subject: [PATCH 2/6] Add streamlit demo program From 5a139ec416e1cebc28b0b0e00e1138bc78f42ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 07:03:55 +0000 Subject: [PATCH 3/6] Add streamlit demo program From 1c9949f157829b73174ecd6161e8e99d50a26abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 07:40:28 +0000 Subject: [PATCH 4/6] add streamlist app --- students.json | 22 ---- weather.json | 290 +++++++++++++++++++++++++++++++++++++++++++++++++ weather_api.py | 15 +++ 3 files changed, 305 insertions(+), 22 deletions(-) delete mode 100644 students.json create mode 100644 weather.json create mode 100644 weather_api.py diff --git a/students.json b/students.json deleted file mode 100644 index 4c430f1..0000000 --- a/students.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "students": [ - { - "id": 1, - "name": "Alice", - "age": 20, - "grades": { - "math": 90, - "science": 85 - } - }, - { - "id": 2, - "name": "Bob", - "age": 22, - "grades": { - "math": 75, - "science": 80 - } - } - ] -} diff --git a/weather.json b/weather.json new file mode 100644 index 0000000..3910dba --- /dev/null +++ b/weather.json @@ -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" + } + ] + } +} \ No newline at end of file diff --git a/weather_api.py b/weather_api.py new file mode 100644 index 0000000..2c61b64 --- /dev/null +++ b/weather_api.py @@ -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"]) \ No newline at end of file From c3b063772eb4de63e9ae37ea2318c327fad14091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 07:42:53 +0000 Subject: [PATCH 5/6] 11 --- weather_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weather_api.py b/weather_api.py index 2c61b64..30057cd 100644 --- a/weather_api.py +++ b/weather_api.py @@ -11,5 +11,5 @@ print(result.status_code) print(result_dict["humidity"]) -#print(result_dict["humidity"]["data"][0]) -#print(result_dict["humidity"]["data"][0]["value"]) \ No newline at end of file +print(result_dict["humidity"]["data"][0]) +print(result_dict["humidity"]["data"][0]["value"]) \ No newline at end of file From 8386505c53033e74c93f7e80e17f3a101fbe816e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 15:43:28 +0800 Subject: [PATCH 6/6] Added Dev Container Folder --- .devcontainer/devcontainer.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d2cb27a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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