首页 > 代码库 > 【同学用了都说吼】国考可报职位筛选脚本
【同学用了都说吼】国考可报职位筛选脚本
今天帮舍友筛选国考可报职位,用Python写了个脚本。筛选条件如下:
1、专业涉法学或法律
2、“仅限本科”的条目删除
3、工作年限无要求
思路:
单纯。
0、获得sheet表头,确定(专业、工作经验、学历)的所在列
1、遍历每个表的表项,将符合条件的行加入结果中。
注:为方便大家直接使用,我把执行结果output.xls放在了这个地址:
https://github.com/shadowmydx/PythonMagic/
大家直接对output.xls 另存为即可。
欢迎报告BUG或者提出需求,我会尽快解决
代码:
# -*- coding:utf-8 -*-
from xlrd import open_workbook,cellname
import xlwt
wd = open_workbook(r‘C:\Users\user\Desktop\DevelopMent\python\gongwuyuan\2015.xls‘)
professional = (u‘专业‘,u‘法律‘,u‘法学‘)
workExperience = (u‘基层工作最低年限‘,u‘无限制‘)
degree = (u‘学历‘,u‘仅限本科‘)
mainCol = [] # save what cols are p & w in.
tablehead = [] # save all cols‘s names.
resultTable = [] # suitable res are in this table.
writeFile = xlwt.Workbook() #
def getTableHead(sheet):
for colIndex in range(sheet.ncols):
tmp = sheet.cell(0,colIndex).value
if tmp == professional[0]:
mainCol.append(colIndex)
if tmp == workExperience[0]:
mainCol.append(colIndex)
if tmp == degree[0]:
mainCol.append(colIndex)
tablehead.append(tmp)
def findSuitRow(sheet):
startRow = 1
for rowIndex in range(startRow,sheet.nrows):
tar1 = sheet.cell(rowIndex,mainCol[0]).value
tar2 = sheet.cell(rowIndex,mainCol[1]).value
tar3 = sheet.cell(rowIndex,mainCol[2]).value
if (tar1.find(professional[1]) != -1 or tar1.find(professional[2]) != -1) and tar3 == workExperience[1] and tar2.find(degree[1]) == -1:
resultTable.append(rowIndex)
def printResult(sheet):
tmpTable = writeFile.add_sheet(sheet.name)
for inx,key in enumerate(tablehead):
tmpTable.write(0,inx,key)
startRow = 1
for key in resultTable:
for colIndex in range(sheet.ncols):
tmpTable.write(startRow,colIndex,sheet.cell(key,colIndex).value)
startRow += 1
def main():
global mainCol
global resultTable
global tablehead
for sheet in wd.sheets():
getTableHead(sheet)
findSuitRow(sheet)
printResult(sheet)
mainCol = []
resultTable = []
tablehead = []
writeFile.save(r‘C:\Users\user\Desktop\DevelopMent\python\gongwuyuan\output.xls‘)
main()
【同学用了都说吼】国考可报职位筛选脚本