File size: 1,827 Bytes
6690bf8 9395971 befab1c 9395971 6690bf8 9395971 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import os
from typing import Dict
import json
from prettytable import PrettyTable
class ConfigManager:
def __init__(self, firebase_api_key: str, firebase_url: str):
"""Khởi tạo với 2 biến secret"""
self.config = {
"FIREBASE_API_KEY": firebase_api_key,
"FIREBASE_URL": firebase_url
}
def read_config(self) -> Dict:
"""Đọc các biến hiện tại"""
return self.config
def update_config(self, key: str, value: str) -> bool:
"""Cập nhật giá trị của biến"""
if key in self.config:
self.config[key] = value
return True
return False
def display_config(self):
"""Hiển thị các biến một cách đẹp mắt"""
table = PrettyTable()
table.field_names = ["Variable", "Value"]
table.align["Variable"] = "l"
table.align["Value"] = "l"
for key, value in self.config.items():
table.add_row([key, value])
print("\nCurrent Configuration:")
print(table)
def main():
# Nhận giá trị ban đầu từ người dùng hoặc môi trường
api_key = os.environ.get("FIREBASE_API_KEY", "your_default_api_key")
url = os.environ.get("FIREBASE_URL", "your_default_url")
# Tạo instance của ConfigManager
config = ConfigManager(api_key, url)
# Hiển thị giá trị ban đầu
config.display_config()
# Ví dụ cập nhật giá trị
print("\nUpdating values...")
config.update_config("FIREBASE_API_KEY", "new_api_key_123")
config.update_config("FIREBASE_URL", "https://new-firebase-url.com")
# Hiển thị giá trị sau khi cập nhật
config.display_config()
if __name__ == "__main__":
main() |