|
@@ -13,108 +13,28 @@ CREATE TABLE IF NOT EXISTS `text` (
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
```
|
|
```
|
|
|
|
|
|
-## 获取sql数据表 text 中所有脚本文件的代码
|
|
|
|
-![get.PNG][2]
|
|
|
|
-
|
|
|
|
-### `getsh.py`
|
|
|
|
|
|
+## 统一设置 MYSQL密码配置 `conf.py`
|
|
```
|
|
```
|
|
-import mysql.connector
|
|
|
|
-conn = mysql.connector.connect(
|
|
|
|
- host="127.0.0.1",
|
|
|
|
- user="user",
|
|
|
|
- passwd="passwd" )
|
|
|
|
-c = conn.cursor()
|
|
|
|
-c.execute("USE vps2022")
|
|
|
|
|
|
+# conn = mysql.connector.connect
|
|
|
|
|
|
-sql = 'SELECT * FROM text ORDER BY name'
|
|
|
|
-c.execute(sql)
|
|
|
|
-text = c.fetchall()
|
|
|
|
|
|
+host="188.188.188.188"
|
|
|
|
+user="root"
|
|
|
|
+passwd="passwd@passwd"
|
|
|
|
+port=3306
|
|
|
|
|
|
-def makefile(file, str):
|
|
|
|
- f = open(file, 'w')
|
|
|
|
- f.write(str); f.close()
|
|
|
|
|
|
+```
|
|
|
|
|
|
-for i in range(len(text)):
|
|
|
|
- file=text[i][0]
|
|
|
|
- file_str = text[i][3]
|
|
|
|
- makefile(file, file_str)
|
|
|
|
- print(file, "\t保存完成!")
|
|
|
|
|
|
+## 获取sql数据表 text 中所有脚本文件的代码 `getsh.py`
|
|
|
|
+![get.PNG][2]
|
|
|
|
|
|
-conn.close()
|
|
|
|
-```
|
|
|
|
|
|
|
|
## 选择下载一个文件 `getfile.py`
|
|
## 选择下载一个文件 `getfile.py`
|
|
![getfile.PNG][4]
|
|
![getfile.PNG][4]
|
|
|
|
|
|
-```
|
|
|
|
-import mysql.connector
|
|
|
|
-conn = mysql.connector.connect(
|
|
|
|
- host="127.0.0.1",
|
|
|
|
- user="user", passwd="pswd",
|
|
|
|
- database="vps2022", buffered = True )
|
|
|
|
-c = conn.cursor()
|
|
|
|
-
|
|
|
|
-sql = 'SELECT name FROM text'
|
|
|
|
-c.execute(sql)
|
|
|
|
-names = c.fetchall()
|
|
|
|
-
|
|
|
|
-# 显示所有文件名,以供下载
|
|
|
|
-for i in range(len(names)):
|
|
|
|
- print(names[i][0], end=' ')
|
|
|
|
-
|
|
|
|
-print('\n:: 选择一个文件下载,输入文件名: ', end='')
|
|
|
|
-name = input().strip()
|
|
|
|
-
|
|
|
|
-sql = 'SELECT * FROM text WHERE name="' + name +'"'
|
|
|
|
-c.execute(sql)
|
|
|
|
-text = c.fetchall()
|
|
|
|
-
|
|
|
|
-def makefile(file, str):
|
|
|
|
- f = open(file, 'w')
|
|
|
|
- f.write(str); f.close()
|
|
|
|
-
|
|
|
|
-for i in range(len(text)):
|
|
|
|
- file=text[i][0]
|
|
|
|
- file_str = text[i][5]
|
|
|
|
- makefile(file, file_str)
|
|
|
|
- print(file, "\t保存完成!")
|
|
|
|
-
|
|
|
|
-conn.close()
|
|
|
|
-```
|
|
|
|
|
|
|
|
## 使用 `addfile.py` 可以批量上传文件到数据库中
|
|
## 使用 `addfile.py` 可以批量上传文件到数据库中
|
|
![addfile.PNG][6]
|
|
![addfile.PNG][6]
|
|
|
|
|
|
-```
|
|
|
|
-import sys, glob
|
|
|
|
-import mysql.connector
|
|
|
|
-conn = mysql.connector.connect(
|
|
|
|
- host="127.0.0.1",
|
|
|
|
- user="user", passwd="passwd",
|
|
|
|
- database="vps2022", buffered = True )
|
|
|
|
-c = conn.cursor()
|
|
|
|
-
|
|
|
|
-files = []
|
|
|
|
-for f in sys.argv[1:]:
|
|
|
|
- files = files + glob.glob(f)
|
|
|
|
-
|
|
|
|
-def readfile(file):
|
|
|
|
- f = open(file, 'r')
|
|
|
|
- str = f.read(); f.close()
|
|
|
|
- return str
|
|
|
|
-
|
|
|
|
-for file in files:
|
|
|
|
- file_str = readfile(file)
|
|
|
|
- row =(file, file_str)
|
|
|
|
-
|
|
|
|
- c.execute("DELETE FROM text WHERE name=%s ", (file,) )
|
|
|
|
- c.execute('INSERT INTO text VALUES (%s,%s)', row)
|
|
|
|
- print("FontName: " + file + " ....OK")
|
|
|
|
-
|
|
|
|
-conn.commit()
|
|
|
|
-conn.close()
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
|
|
|
|
[1]: https://262235.xyz/usr/uploads/2021/12/1283040383.png
|
|
[1]: https://262235.xyz/usr/uploads/2021/12/1283040383.png
|
|
[2]: https://262235.xyz/usr/uploads/2021/12/2063028572.png
|
|
[2]: https://262235.xyz/usr/uploads/2021/12/2063028572.png
|