timmy / 台灣假日 API 查詢與快取
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
這段程式碼是一個節假日查詢工具,從指定 API 獲取節假日資料,支援緩存與分頁,並提供按年份篩選節假日、檢查特定日期是否為節假日的功能,同時以 Holiday 類別封裝每個節假日的詳細資訊,便於操作與顯示。
| 1 | import requests |
| 2 | import os |
| 3 | import json |
| 4 | |
| 5 | class HolidayAPI: |
| 6 | def __init__(self, base_url, cache_dir="cache"): |
| 7 | """ |
| 8 | Initialize the HolidayAPI class. |
| 9 | :param base_url: The base URL for the API endpoint. |
| 10 | :param cache_dir: Directory to store cached data. |
timmy / Python 虛擬環境設定(venv)
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
此 JSON 配置檔案用於設定 Python 虛擬環境 (venv) 的路徑,適用於編輯器(如 VS Code),確保 Python 解譯器和專案依賴管理在指定的虛擬環境 .venv 中執行。
| 1 | { |
| 2 | "venvPath": ".", |
| 3 | "venv": ".venv" |
| 4 | } |
timmy / IP 位址查詢與解析
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
這個 Bash 腳本用於 查詢目前裝置的公網 IP 及其地理資訊。它會先檢查系統是否安裝了 curl 和 jq(jq 用於解析 JSON),然後使用 curl 向 ip-api.com 發送請求,獲取目前裝置的 IP 位址、國家、城市、ISP、時區等資訊,並透過 jq 以可讀格式輸出。這適用於 網路診斷、IP 追蹤、地理位置查詢或伺服器網路狀態檢測。
| 1 | #!/bin/bash |
| 2 | |
| 3 | SHELL=/bin/sh |
| 4 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 5 | TZ="Asia/Taipei" |
| 6 | export PATH |
| 7 | export LANG=en_US.UTF-8 |
| 8 | export LANGUAGE=en_US:en |
| 9 | |
| 10 | # Check if curl is installed |
timmy / 策略模式實作 YAML 與 JSON 資料處理
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
這段 Python 程式碼使用 策略模式(Strategy Pattern),定義一個 DataHandlerStrategy 介面,並實作 YAML (YamlHandler) 與 JSON (JsonHandler) 兩種不同的資料處理策略。它提供統一的 read_data 和 write_data 方法,讓程式可以根據不同的檔案格式 靈活讀取與寫入 YAML 或 JSON 檔案,適用於 配置管理、資料序列化或跨格式資料處理應用。
| 1 | import yaml |
| 2 | import json |
| 3 | from abc import ABC, abstractmethod |
| 4 | |
| 5 | # 策略介面 |
| 6 | class DataHandlerStrategy(ABC): |
| 7 | @abstractmethod |
| 8 | def read_data(self, path): |
| 9 | pass |
timmy / 策略模式在資料管理中的應用
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
此範例展示策略模式在 YAML 和 JSON 資料處理中的應用,DataHandlerStrategy 定義通用的讀寫介面,並透過 YamlHandler 和 JsonHandler 來處理不同格式的資料。DataManager 負責管理資料存取,並可動態切換處理策略,提高靈活性與可維護性。
| 1 | import time |
| 2 | import yaml |
| 3 | import json |
| 4 | from abc import ABC, abstractmethod |
| 5 | import streamlit as st |
| 6 | |
| 7 | # 策略介面 |
| 8 | class DataHandlerStrategy(ABC): |
| 9 | @abstractmethod |
| 10 | def read_data(self, path): |
timmy / Streamlit 使用者驗證系統
0 gustos
0 bifurcaciones
1 archivos
Última actividad 10 months ago
| 1 | import json |
| 2 | from abc import ABC, abstractmethod |
| 3 | |
| 4 | import streamlit as st |
| 5 | import streamlit_authenticator as stauth |
| 6 | import yaml |
| 7 | |
| 8 | |
| 9 | # 策略介面 |
| 10 | class DataHandlerStrategy(ABC): |
Siguiente
Anterior