现要用python写一个程序。1.从数据库中获取当前在线订单的型号;2.根据获取的型号从某个文件服务器的文件夹内找到对应的型号;3.从对应型号文件夹的MI文件夹中找到外形及v-cut图纸;4.将图纸复制到另一个服务器的指定文件夹中中对应型号的文件夹里;5.每12小时执行一次
时间: 2024-05-07 13:16:16 浏览: 63
以下是一个简单的Python程序,实现上述要求:
```python
import os
import shutil
import time
import mysql.connector
# 连接数据库
cnx = mysql.connector.connect(user='username', password='password', host='localhost', database='database')
cursor = cnx.cursor()
# 获取当前在线订单的型号
query = ("SELECT model FROM orders WHERE status = 'online'")
cursor.execute(query)
result = cursor.fetchall()
for row in result:
model = row[0]
# 从文件服务器的文件夹内找到对应的型号
file_path = '/fileserver/' + model
if os.path.exists(file_path):
# 从对应型号文件夹的MI文件夹中找到外形及v-cut图纸
mi_folder = os.path.join(file_path, 'MI')
outline_file = os.path.join(mi_folder, 'outline.pdf')
vcut_file = os.path.join(mi_folder, 'vcut.pdf')
if os.path.exists(outline_file) and os.path.exists(vcut_file):
# 将图纸复制到另一个服务器的指定文件夹中中对应型号的文件夹里
dest_folder = '/destserver/' + model
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
shutil.copy2(outline_file, dest_folder)
shutil.copy2(vcut_file, dest_folder)
# 关闭数据库连接
cursor.close()
cnx.close()
# 每12小时执行一次
while True:
time.sleep(12 * 60 * 60)
# 重复上述步骤
```
请注意,此程序仅供参考,并且需要根据实际情况进行修改,例如数据库连接信息、文件服务器路径、目标服务器路径等。
阅读全文
相关推荐









