‘模拟的中国985高校核心科研内容网站’自动化构建脚本

This commit is contained in:
free will
2020-10-30 21:18:51 +08:00
commit c87d1fd3ac
30 changed files with 13849 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
.git/
.idea/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
import os
import xlsxwriter
import xlrd
# 读取excel文件某一列
def readExcelByCol(path, i):
i_col_content = []
worksheet = xlrd.open_workbook(path)
sheet_names = worksheet.sheet_names()
print(sheet_names)
for sheet_name in sheet_names:
sheet = worksheet.sheet_by_name(sheet_name)
rows = sheet.nrows # 获取行数
print(rows)
for j in range(rows):
i_col_content.append(sheet.cell_value(j, i))
return i_col_content
# 创建excel文件
def mkExcel(path):
workbook = xlsxwriter.Workbook(path)
workbook.close()
print("--- Created excel success" + path + " ---")
# 创建新文件。如果原来已经存在文件,则覆盖掉原有文件
def mkfileCoverOriginFile(path,content):
file = open(path, 'w')
file.write(content)
file.close()
print("--- Created file success" + path + " ---")
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
import os
def mkdir(path):
folder = os.path.exists(path)
if not folder: # 判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(path) # makedirs 创建文件时如果路径不存在会创建这个路径
print("--- Created folder success" + path + " ---")
else:
print("--- There is this folder: " + path + " ---")
Binary file not shown.
+34
View File
@@ -0,0 +1,34 @@
import random
import FileManager
# 生成一个人名
def generatorPersonName():
dataPath = '.\\Data\\PersonName\\HistoryName.txt'
with open(dataPath, 'r+', encoding='utf-8') as f:
lines = f.readlines()
lineslen= len(lines)
luckyNum=random.randint(0,lineslen-1)
print(lines[luckyNum].split()[0])
return lines[luckyNum].split()[0]
# 根据所属领域,生成一个实验室名称
def generatorLabNameBySubjectArea(subjectArea):
dataPath = '.\\Data\\Labs\\'
labnameList = FileManager.readExcelByCol(dataPath+subjectArea+"实验室.xlsx", 0)
luckyNum=random.randint(0, len(labnameList)-1)
print(labnameList[luckyNum]+"实验室")
return labnameList[luckyNum]+"实验室"
# 根据学院获取所属领域,根据领域获取实验室名称
def generatorLabNameByCollegeName(collegeName):
dataPath= '.\\Data\\学院.xlsx'
collegeList=FileManager.readExcelByCol(dataPath, 0)
areaList=FileManager.readExcelByCol(dataPath,1)
collegeIndex=collegeList.index(collegeName)
subjectArea=areaList[collegeIndex]
print(subjectArea)
return generatorLabNameBySubjectArea(subjectArea)
# generatorPersonName()
# generatorLabName("信息领域")
# generatorLabNameByCollegeName("工程学院")
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
import FileManager
import FolderManager
University985 = "985院校名单"
#
uList = FileManager.readExcelByCol("D:\\Test\\"+"学院"+".xlsx", 0)
for i in range(len(uList)):
FileManager.mkExcel("D:\\Test\\"+uList[i]+".xlsx")
# folderTest = "D:\\Test"
# FolderManager.mkdir(folderTest)
# fileTest="D:\\Test\\test.txt"
# FileManager.mkfileCoverOriginFile(fileTest,"hello,content")
# FileManager.mkExcel("D:\\Test\\test.xlsx")
+93
View File
@@ -0,0 +1,93 @@
import FileManager
import FolderManager
import NameGenerator
targetDir = "D:\\Test\\"
dataRootDir = ".\\Data\\"
University985_FileName = "985院校名单"
College_FileName = "学院"
# Department_FileName = "系"
Lab_FileName = "实验室"
excelFileExtension = ".xlsx"
# 创建个人文件夹
# nums: 要创建的个人文件夹的个数
# targetDir: 将创建的文件夹放在的目录
def creatPersonDir(nums, targetDir):
# 循环创建文件夹
for i in range(nums):
# 获取一个随机人名
personName = NameGenerator.generatorPersonName()
# 创建个人文件夹
FolderManager.mkdir(targetDir + personName.strip())
# 在该文件夹下创建一个文件
FileManager.mkfileCoverOriginFile(targetDir + personName.strip() + "\\" + personName.strip() + ".txt",
"This is " + personName.strip() + "'s file.")
# 创建实验室目录
# collegeName: 实验室所属学院的名称
# nums: 要创建的实验室的个数
# targetDir: 将创建的文件夹放在的目录
def creatLabDir(collegeName, nums, targetDir):
# 循环创建文件夹
for i in range(nums):
# 根据学院获取所属领域,根据领域获取实验室名称
labName = NameGenerator.generatorLabNameByCollegeName(collegeName)
# 创建各个实验室文件夹
FolderManager.mkdir(targetDir + labName.strip())
# 在该实验室文件夹下创建个人文件夹
creatPersonDir(10, targetDir + labName.strip() + "\\")
return True
# 创建专业目录
# dataDir: 专业列表的文件所在位置
# targetDir: 将创建的文件夹放在的目录
def creatDepartmentDir(dataDir, targetDir, collegeName):
# 从文件中获取专业名单
dList = FileManager.readExcelByCol(dataDir, 0)
# 循环创建文件夹
for i in range(len(dList)):
# 创建各个专业文件夹
FolderManager.mkdir(targetDir + dList[i].strip())
# 在该专业文件夹下创建实验室文件夹
creatLabDir(collegeName, 10, targetDir + dList[i].strip() + "\\")
return True
# 创建学院目录
# dataDir: 学院列表的文件所在位置
# targetDir: 将创建的文件夹放在的目录
def creatCollegeDir(dataDir, targetDir):
# 从文件中获取学院名单
cList = FileManager.readExcelByCol(dataDir, 0)
# 循环创建文件夹
for i in range(len(cList)):
# 创建各个学院文件夹
FolderManager.mkdir(targetDir + cList[i].strip())
# 在该学院文件夹下创建专业子文件夹
creatDepartmentDir(dataRootDir + "college\\" + cList[i].strip() + excelFileExtension, targetDir + cList[i].strip() + "\\",
cList[i].strip())
return True
# 创建大学目录
# dataDir: 大学列表的文件所在位置
# targetDir: 将创建的文件夹放在的目录
def creatUniversityDir(dataDir, targetDir):
# 从文件中获取大学名单
uList = FileManager.readExcelByCol(dataDir, 0)
# 循环创建文件夹
for i in range(len(uList)):
# 创建各个大学文件夹
FolderManager.mkdir(targetDir + uList[i].strip())
# 在该大学文件夹下创建学院子文件夹
creatCollegeDir(dataRootDir + College_FileName + excelFileExtension, targetDir + uList[i].strip() + "\\")
return True
flag = creatUniversityDir(dataRootDir + University985_FileName + excelFileExtension,targetDir)
print("目录创建完成")