aliapi/utils/loadconfig.py
2025-02-05 14:27:23 +08:00

37 lines
1.2 KiB
Python

from configparser import ConfigParser
import os
ENVIRONMENT_VARIABLE = os.getenv("ENVIRONMENT_VARIABLE", 996)
def get_path():
current_directory = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
return root_path
def get_pg_config():
conf = ConfigParser()
conf.read(get_path() + '/config/config.ini')
return {
"database": conf[ENVIRONMENT_VARIABLE]['database'],
"user": conf[ENVIRONMENT_VARIABLE]['user'],
"password": conf[ENVIRONMENT_VARIABLE]['password'],
"host": conf[ENVIRONMENT_VARIABLE]['host'],
"port": conf[ENVIRONMENT_VARIABLE]['port'],
# 设置默认超时时间statement_timeout=五分钟
"options":"-c statement_timeout=500000 -c idle_in_transaction_session_timeout=600000"
}
def get_ali_config(ENVIRONMENT_VARIABLE):
conf = ConfigParser()
conf.read(get_path() + '/config/config.ini')
return {
"access_key_id": conf[ENVIRONMENT_VARIABLE]['access_key_id'],
"access_key_secret": conf[ENVIRONMENT_VARIABLE]['access_key_secret'],
"endpoint": conf[ENVIRONMENT_VARIABLE]['endpoint']
}
if __name__ == '__main__':
print(get_ali_config())