timmy / YAML 檔案讀寫與資料管理
1 likes
0 forks
1 files
Last active 10 months ago
這段程式碼提供了一個 YAMLProcessor 類別,負責讀取和寫入 YAML 檔案(預設為 local_data.yaml),並將其內容轉換為 pandas.DataFrame 進行處理,適用於需要以表格形式操作 YAML 資料的應用場景。
| 1 | import os |
| 2 | import yaml |
| 3 | import pandas as pd |
| 4 | import logging |
| 5 | from typing import Any, Dict, List |
| 6 | |
| 7 | # 設定 logging 基本參數 |
| 8 | logging.basicConfig(level=logging.INFO) |
| 9 | logger = logging.getLogger(__name__) |
timmy / 策略模式實作 YAML 與 JSON 資料處理
0 likes
0 forks
1 files
Last active 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 likes
0 forks
1 files
Last active 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 likes
0 forks
1 files
Last active 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): |
timmy / 使用 Streamlit 建立 YAML 員工資料管理系統
0 likes
0 forks
2 files
Last active 10 months ago
此程式使用 Streamlit 讀取、編輯並儲存員工資料至 YAML 檔案,提供直覺化 UI 介面,並支援欄位過濾與年齡篩選,適用於企業資料管理。
| 1 | employees: |
| 2 | - Age: 34 |
| 3 | City: New York |
| 4 | Name: Alice |
| 5 | Occupation: Engineer |
| 6 | Salary: 70000 |
| 7 | - Age: 27 |
| 8 | City: Los Angeles |
| 9 | Name: Bob |
| 10 | Occupation: Doctor |
timmy / 使用 Streamlit 建立 YAML 編輯器
0 likes
0 forks
1 files
Last active 10 months ago
此程式使用 Streamlit 讓使用者讀取、編輯並儲存 YAML 文件,透過 pandas 轉換為表格格式,適用於設定檔管理與資料編輯工具。
| 1 | from io import StringIO |
| 2 | |
| 3 | import pandas as pd |
| 4 | import streamlit as st |
| 5 | import yaml |
| 6 | |
| 7 | |
| 8 | # 定義 YamlHandler 類 |
| 9 | class YamlHandler: |
| 10 | def __init__(self, file_path): |
timmy / 使用 Streamlit 建立 YAML 設定檔編輯器
0 likes
0 forks
2 files
Last active 10 months ago
此程式使用 Streamlit 讀取、編輯並存儲 YAML 設定檔,透過 pandas 轉換為表格格式,提供直覺化 UI 介面,適用於設定管理與資料修改。
| 1 | age: 30 |
| 2 | is_active: true |
| 3 | name: John Doe |
timmy / 使用 Streamlit 建立使用者身份驗證系統
0 likes
0 forks
2 files
Last active 10 months ago
這段程式碼使用 Streamlit 和 streamlit-authenticator 來 管理使用者登入,透過 YAML 設定檔 儲存使用者憑證與 Cookie 配置,並提供 登入、登出 和 使用者驗證 功能。
| 1 | cookie: |
| 2 | expiry_days: 30 |
| 3 | key: some_signature_key |
| 4 | name: my_auth_cookie |
| 5 | credentials: |
| 6 | usernames: |
| 7 | jsmith: |
| 8 | email: jsmith@gmail.com |
| 9 | failed_login_attempts: 0 # Will be managed automatically |
| 10 | logged_in: False # Will be managed automatically |
Newer
Older