v.0.11.1 --network=dev-network for conatiners
This commit is contained in:
@@ -6,6 +6,10 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"dockerfile": "Dockerfile"
|
"dockerfile": "Dockerfile"
|
||||||
},
|
},
|
||||||
|
"runArgs": [
|
||||||
|
"--network=dev-network",
|
||||||
|
"--name=api-server"
|
||||||
|
],
|
||||||
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
|
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
|
||||||
// "image": "python:latest",
|
// "image": "python:latest",
|
||||||
//"image": "python:3.13-slim",
|
//"image": "python:3.13-slim",
|
||||||
@@ -37,8 +41,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
"postCreateCommand": "uv sync"
|
"postCreateCommand": "uv sync",
|
||||||
// "postCreateCommand": "apt-get update && apt-get install -y git && pip3 install -r requirements.txt"
|
// "postCreateCommand": "apt-get update && apt-get install -y git && pip3 install -r requirements.txt"
|
||||||
|
"postStartCommand": "uv run app/main.py" // Add this line
|
||||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
// "remoteUser": "root"
|
// "remoteUser": "root"
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,10 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"dockerfile": "Dockerfile"
|
"dockerfile": "Dockerfile"
|
||||||
},
|
},
|
||||||
|
"runArgs": [
|
||||||
|
"--network=dev-network",
|
||||||
|
"--name=pico-client"
|
||||||
|
],
|
||||||
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
|
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
|
||||||
// "image": "python:latest",
|
// "image": "python:latest",
|
||||||
//"image": "python:3.13-slim",
|
//"image": "python:3.13-slim",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import random
|
||||||
from display import NeoPixel_64x64
|
from display import NeoPixel_64x64
|
||||||
from display.fonts import font_5x7
|
from display.fonts import font_5x7
|
||||||
from tryout import Font_Checker, Weather_Checker, Emoji_Checker, API_Server_Checker
|
from tryout import Font_Checker, Weather_Checker, Emoji_Checker, API_Server_Checker
|
||||||
@@ -22,7 +23,15 @@ async def weather_check_task(weather_checker: Weather_Checker):
|
|||||||
for city in CITY_LIST:
|
for city in CITY_LIST:
|
||||||
weather_checker.check(city=city, lang="de", test_mode=True)
|
weather_checker.check(city=city, lang="de", test_mode=True)
|
||||||
print(f"Checked {city}")
|
print(f"Checked {city}")
|
||||||
await asyncio.sleep(3 * 60) # Non-blocking sleep
|
await asyncio.sleep(3 * 60)
|
||||||
|
|
||||||
|
|
||||||
|
async def api_server_check_task(api_server_checker: API_Server_Checker):
|
||||||
|
while True:
|
||||||
|
rnd_item_id: int = random.randrange(4)
|
||||||
|
|
||||||
|
api_server_checker.check(rnd_item_id)
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
async def print_time_task() -> None:
|
async def print_time_task() -> None:
|
||||||
@@ -44,10 +53,15 @@ async def sync_ntp_time_task() -> None:
|
|||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
async def main(weather_checker: Weather_Checker) -> None:
|
async def main(
|
||||||
|
weather_checker: Weather_Checker, api_server_checker: API_Server_Checker
|
||||||
|
) -> None:
|
||||||
# Run both tasks concurrently
|
# Run both tasks concurrently
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
sync_ntp_time_task(), weather_check_task(weather_checker), print_time_task()
|
sync_ntp_time_task(),
|
||||||
|
weather_check_task(weather_checker),
|
||||||
|
api_server_check_task(api_server_checker),
|
||||||
|
print_time_task(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -63,11 +77,9 @@ if __name__ == "__main__":
|
|||||||
# emoji_checker : Emoji_Checker = Emoji_Checker(display)
|
# emoji_checker : Emoji_Checker = Emoji_Checker(display)
|
||||||
# emoji_checker.check()
|
# emoji_checker.check()
|
||||||
|
|
||||||
api_server_check_task: API_Server_Checker = API_Server_Checker()
|
|
||||||
api_server_check_task.check()
|
|
||||||
|
|
||||||
display.set_font(font_5x7)
|
display.set_font(font_5x7)
|
||||||
weather_checker: Weather_Checker = Weather_Checker(display=display)
|
weather_checker: Weather_Checker = Weather_Checker(display=display)
|
||||||
|
api_server_checker: API_Server_Checker = API_Server_Checker()
|
||||||
|
|
||||||
# show_system_load()
|
# show_system_load()
|
||||||
asyncio.run(main(weather_checker))
|
asyncio.run(main(weather_checker, api_server_checker))
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
import urequests # type: ignore
|
import urequests # type: ignore
|
||||||
import json
|
import json
|
||||||
|
|
||||||
BASE_API_URL: str = "http://0.0.0.0:8000"
|
BASE_API_URL: str = "http://api-server:8000"
|
||||||
|
|
||||||
|
|
||||||
class API_Server_Checker:
|
class API_Server_Checker:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_items(self):
|
def _get_items(self, item_id: int = 0):
|
||||||
items_url: str = f"{BASE_API_URL}/items"
|
items_url: str = (
|
||||||
|
f"{BASE_API_URL}/items"
|
||||||
|
if item_id == 0
|
||||||
|
else f"{BASE_API_URL}/items/{item_id}"
|
||||||
|
)
|
||||||
print(f"query: {items_url}")
|
print(f"query: {items_url}")
|
||||||
r = urequests.get(items_url)
|
r = urequests.get(items_url)
|
||||||
print("Status-Code:", r.status_code)
|
print("Status-Code:", r.status_code)
|
||||||
json_resp = r.json()
|
json_resp = r.json()
|
||||||
print("json_resp:", json_resp)
|
|
||||||
|
|
||||||
def check(self):
|
if r.status_code == 200:
|
||||||
self._get_items()
|
print("json_resp:", json_resp)
|
||||||
|
else:
|
||||||
|
print("api-server error:", json_resp["error"]["message"])
|
||||||
|
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
def check(self, item_id: int):
|
||||||
|
self._get_items(item_id)
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ class DigitalClock:
|
|||||||
fresh_part: str = time_str[mismatch_pos:]
|
fresh_part: str = time_str[mismatch_pos:]
|
||||||
part_to_clear: str = self.stored_time_str[mismatch_pos:]
|
part_to_clear: str = self.stored_time_str[mismatch_pos:]
|
||||||
|
|
||||||
print(f"untouched_part: {untouched_part}[{part_to_clear}-->{fresh_part}] ")
|
|
||||||
|
|
||||||
textwidth: int = self._text_width(self.stored_time_str)
|
textwidth: int = self._text_width(self.stored_time_str)
|
||||||
print(f"{self.stored_time_str}: #{textwidth}")
|
print(f"{self.stored_time_str}: #{textwidth}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user