Skip to content

Commit de2acb0

Browse files
committed
.env
1 parent 24de15e commit de2acb0

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 這是一個範例檔案,請複製一份 .env.example 並命名為 .env
2+
# 並將以下的設定值填入
3+
MYSQL_USER=資料庫使用者
4+
MYSQL_PASSWORD=資料庫使用者密碼
5+
MYSQL_PORT=資料庫連接埠
6+
MYSQL_DATABASE=資料庫名稱
7+
HOST=資料庫主機位址

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ read.txt
1212
nohup.out
1313
pointLog.out
1414
flakLog.out
15+
.env

cog/core/secret.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
# IMPORTANT!!!!Must ignore git!!!
21
import mysql.connector
2+
import os
3+
from dotenv import load_dotenv
34

5+
load_dotenv(f'{os.getcwd()}/.env')
6+
7+
8+
HOSTIP = os.getenv('HOST')
9+
PORT= os.getenv('MYSQL_PORT')
10+
DBUSER = os.getenv('MYSQL_USER')
11+
DBNAME= os.getenv('MYSQL_DATABASE')
12+
PWD = os.getenv('MYSQL_PASSWORD')
413
def connect():
5-
connection = mysql.connector.connect(
6-
host = "",
7-
port = "",
8-
user = "",
9-
passwd = "",
10-
database = "",
11-
auth_plugin = "mysql_native_password"
14+
connection = mysql.connector.connect(host=HOSTIP,
15+
port=PORT,
16+
user=DBUSER,
17+
passwd=PWD,
18+
database=DBNAME
1219
)
20+
1321
return connection

requirements.txt

142 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)