jcyrss / baiyueheiyu

教程官网地址 www.byhy.net
5 stars 1 forks source link

玉慈流生界天 #7

Open jcyrss opened 4 years ago

jcyrss commented 4 years ago

one prac

hospital.zip

数据.zip

weatherforcast.zip

jcyrss commented 4 years ago

关键就是几个库函数要写对,参考下面

老师发布任务的实现

def teacher_deliver_task(self,  examname):
        self.wd.find_element_by_css_selector(
'.main-menu >ul> li:nth-of-type(2)').click()

        self.wd.find_element_by_css_selector(
'a[ng-click^="show_page_addexam"] span').click()

        time.sleep(2)

        self.wd.find_element_by_id(
'exam_name_text').send_keys(examname)

        self.wd.find_element_by_id('btn_pick_question').click()

        # 点击后界面重新渲染,等待一下
        time.sleep(2)

        # 题目在新的frame中
        self.wd.switch_to.frame('pick_questions_frame')

        # 只需要选前3个
        # 每次选择一题,界面会重新渲染,所以只能循环获取

        for counter in  range(3):
            selectButtons = self.wd.find_elements_by_class_name('btn_pick_question')
            selectButtons[counter].click()
            # 点击后界面重新渲染,等待一下
            time.sleep(1)

        # 点击 OK button
        self.wd.find_element_by_css_selector(
            'div[onclick*="pickQuestionOK"]'
        ).click()

        # 切换回 主 html
        self.wd.switch_to.default_content()

        # 选完题目回到主界面,界面会发生变动,sleep 一下
        time.sleep(1)

        # 点击确定添加
        self.wd.find_element_by_id('btn_submit').click()

        # 选择发布给学生
        self.wd.find_element_by_css_selector(
            '.bootstrap-dialog-footer-buttons  button:nth-child(2)'
        ).click()

        # sleep 一下
        time.sleep(1)

        #保存主窗口handle
        mainWindow = self.wd.current_window_handle

        # 切换到 下发学习任务窗口

        for handle in self.wd.window_handles:
            # 切换到新窗口
            self.wd.switch_to.window(handle)
            # 检查是否是我们要进入的window
            if '下发学习任务' in self.wd.title:
                print('进入到下发任务窗口')
                break

        # sleep 一下
        time.sleep(1)

        # 只有唯一的一位学生,直接勾选即可
        # 注意要选  label.myCheckbox  而不是  input[type=checkbox]
        # 因为后者不可见,调试就会发现问题
        self.wd.find_element_by_css_selector('label.myCheckbox').click()

        # 点击确定下发
        self.wd.find_element_by_css_selector('button[ng-click*=openDispatchDlg]').click()

        # sleep 一下
        time.sleep(1)

        # 点击确定
        self.wd.find_element_by_css_selector('button[ng-click*=dispatchIt]').click()

        # 下一个确定
        self.wd.find_element_by_css_selector(
            'div.bootstrap-dialog-footer-buttons > button').click()

        # 切回主窗口
        self.wd.switch_to.window(mainWindow)

学生去做练习

def  studentDoExam(self):
        self.wd.find_element_by_css_selector(
'a[href="#/task_manage"] >li').click()

        # 由于数据是异步获取,需要sleep一段时间,假设需求是2秒必须获取数据
        time.sleep(2)

        # 点击打开第一个任务
        self.wd.find_element_by_css_selector(
'button[ng-click*=viewTask]').click()

        # 全部选A
        firstAnwsers = self.wd.find_elements_by_css_selector(
            '.btn-group button:nth-child(1)'
        )

        for one in firstAnwsers:
            one.click()

        self.wd.find_element_by_css_selector('button[ng-click*=saveMyResult]').click()

        # 点击确定
        self.wd.find_element_by_css_selector(
            '.bootstrap-dialog-footer-buttons  button:nth-child(2)'
        ).click()

        time.sleep(2)

老师获取最新提交的学员作业

def teacher_get_latest_student_task(self):
        self.wd.get(
'http://ci.ytesting.com/teacher/index.html#/task_manage?tt=1')

        time.sleep(2)

        # 点击第一个任务查看
        self.wd.find_element_by_css_selector(
            "a[ng-click*=trackTask]"
        ).click()

        time.sleep(1)

        # 点击 第一个学生 查看
        self.wd.find_element_by_css_selector(
            'button[ng-click*="viewTaskTrack"]'
        ).click()

        #保存主窗口handle
        mainWindow = self.wd.current_window_handle

        # 切换到 查看作业窗口

        for handle in self.wd.window_handles:
            # 切换到新窗口
            self.wd.switch_to.window(handle)
            # 检查是否是我们要进入的window
            if '查看作业' in self.wd.title:
                break

        # 勾选的选项会有 .myCheckbox input:checked  Pseudo Classes,
        # 但是这个不出现在 元素html里面
        eles = self.wd.find_elements_by_css_selector('.myCheckbox input:checked')

        selectedchoices = [ele.find_element_by_xpath('./..').text.strip() for ele in eles]

        print(selectedchoices)

        # 切回主窗口
        self.wd.switch_to.window(mainWindow)

        return selectedchoices
jcyrss commented 4 years ago
def moneyconv(money):
    intMoney =  int(money)
    nlist=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
    if len(money)>4:
        print('数字最多为4位')
    #一位数
    if len(money)==1:
        print(nlist[ intMoney])
    #两位数
    if len(money)==2:
        list1=[int( intMoney/10),int( intMoney%10)]
        if list1[1]==0:
            print(nlist[list1[0]]+'拾')
        else:
            print(nlist[list1[0]] + '拾' + nlist[list1[1]])
    #三位数
    if len(money)==3:
        list2=[int( intMoney/100),int(( intMoney%100)/10),int(( intMoney%10)%10)]
        if list2[1]==0 and list2[2]==0:
            print(nlist[list2[0]]+'佰')
        if list2[2]==0 and list2[1]!=0:
            print(nlist[list2[0]]+'佰'+nlist[list2[1]]+'拾')
        if list2[1]==0 and list2[2]!=0:
            print(nlist[list2[0]] +'佰零'+nlist[list2[0]])
        if list2[1]!=0 and list2[2]!=0:
            print(nlist[list2[0]]+'佰'+nlist[list2[1]]+'拾'+nlist[list2[0]])
    #四位数
    if len(money)==4:
        list3=[int( intMoney/1000),int( intMoney%1000/100),int( intMoney%1000%100/10),int( intMoney%1000%100%10)]
        if list3[2]==0 and list3[3]==0 and list3[1]==0:
            print(nlist[list3[0]]+'仟')
        if list3[1]==0 and list3[2]==0 and list3[3]!=0:
            print(nlist[list3[0]]+'仟零'+nlist[list3[3]])
        if list3[1]==0 and list3[2]!=0 and list3[3]==0:
            print(nlist[list3[0]]+'仟零'+nlist[list3[2]] +'拾')
        if list3[1]!=0 and list3[2]==0 and list3[3]==0:
            print(nlist[list3[0]]+'仟'+nlist[list3[1]] +'佰')
        if nlist[1]!=0 and list3[2]!=0 and list3[3]!=0:
            print(nlist[list3[0]]+'仟'+nlist[list3[1]] +'佰'+nlist[list3[2]] +'拾'+nlist[list3[3]])
jcyrss commented 4 years ago
def convert4digits(money):
    lenthmoney = len(money)    
    font= '零壹贰叁肆伍陆柒捌玖拾'
    if lenthmoney > 4:
        print('数字最多4位!')
        return

#1位的数字
    if lenthmoney == 1:    
        money_font = font[int(money)]
#2位的数字
    elif lenthmoney == 2:
        money_font=font[int(money[0])]+'拾'+font[int(money[1])]
#3位的数字
    elif lenthmoney == 3:
        money_font=font[int(money[0])]+'佰'+font[int(money[1])]+'拾'+font[int(money[2])]
#有4位的数字            
    elif lenthmoney ==4:
        money_font=font[int(money[0])]+'仟'+font[int(money[1])]+'佰'+font[int(money[2])]+'拾'+font[int(money[3])]    
#排除特殊情况
    money_font=money_font.replace('零佰','零')
    money_font=money_font.replace('零拾','零')
    money_font=money_font.replace('零零零','')
    money_font=money_font.replace('零零','零')
    if money_font[-1]=='零':
        money_font=money_font[:-1]
    print(money_font)

convert4digits('3')
convert4digits('87')
convert4digits('300')
convert4digits('807')
convert4digits('1087')
convert4digits('1007')
convert4digits('1010')
convert4digits('1000')

或者

cn_digital = '零壹贰叁肆伍陆柒捌玖'
cn_numeration = ['','拾','佰','仟','万','十万','百万','千万','亿']

def convert4digits(num):
    # 判断是否全为数字
    if not num.isdigit():
        return print('请输入正确的数字')

    list_num = []

    n = 0
    flg = True
    for i in num[::-1]:
        if i!='0':
            list_num.append(cn_digital[int(i)] + cn_numeration[n])
            flg = True
        else:
            if flg:
                list_num.append('零')
                flg = False
        n +=1
    list_num.reverse()
    if list_num[-1]=='零' and len(list_num) !=1:
        list_num.pop(-1)
    return print(''.join(list_num))
jcyrss commented 4 years ago

stock.zip cad.zip

jcyrss commented 4 years ago
import os

targetDir = './data'

# 标题栏
heads = ['路径','文件名']

# 每行内容对应一个文件 ,每个文件作为一个元素
dataLines = []

# 计数器,记录已经处理了多少个文件
count = 0

# 先把所有数据内容读取到 dataLines中
print('读取数据\n')

# dirpath 代表当前遍历到的目录名
# dirnames 是列表对象,存放当前dirpath中的所有子目录名
# filenames 是列表对象,存放当前dirpath中的所有文件名
for (dirpath, dirnames, filenames) in os.walk(targetDir):
    for fn in filenames:

        # 扩展名不是 inf的直接跳过
        if not fn.endswith('.inf'):
            continue

        # 是inf,处理

        print(f'处理文件 {fn}')

        # 文件内容,存入 dataLine   
        dataLine = {
            '路径'  :  os.path.abspath(dirpath),
            '文件名': fn,
        }

        fpath = os.path.join(dirpath, fn)
        with open(fpath, encoding='gbk') as f:
            content = f.read()

        lines = content.splitlines()
        for line in lines:
            line = line.strip()
            # 跳过空行
            if not line:
                continue

            # 因为冒号后面内容可能还有冒号,所以指定split 1 次
            name, value = line.split(':',1)
            dataLine[name] = value

            if name not in heads:
                heads.append(name)

        #  dataLine  存储了一个inf 文件的内容,放入列表
        dataLines.append(dataLine)

print(heads)

print('\n\n数据写入excel...')        

import openpyxl

# 创建一个Excel workbook 对象
book = openpyxl.Workbook()

# 创建时,会自动产生一个sheet,通过active获取
sh = book.active

# 修改当前 sheet 标题为 工资表
sh.title = 'data'

# 写标题栏
for idx, head in enumerate(heads):
    # 列号是 idx + 1 ,因为从1 开始计数
    sh.cell(1,idx+1).value = head

# 写内容
row = 2 # 行号从2开始
for dl in dataLines:
    # 对每个 head 栏 获取 dl 对应文件里面的值
    for idx, head in enumerate(heads):
        value = dl.get(head,'')
        # 列号是 idx + 1 ,因为从1 开始计数
        sh.cell(row,idx+1).value = value

    row += 1

book.save('信息.xlsx')   
jcyrss commented 4 years ago

stock.txt

jcyrss commented 4 years ago
with open('2019-10-22_11.05.40.log', 'r', encoding='utf8') as f:
    # 定义用来统计的字典
    counterTable = {}

    while True:
        # 一行一行读入,防止大文件,
        line = f.readline()
        # 到达文件末尾
        if len(line) == 0:
            break

        # 空行,跳过
        line = line.strip()
        if not line:
            continue

        parts = line.split('|')
        info = parts[-2]
        if info in counterTable:
            counterTable[info] += 1
        else:
            counterTable[info] = 1

with open('ret.txt', 'w', encoding='utf8') as f:
    for info, count in counterTable.items():
        f.write(f'{info} : {count}个\n')
jcyrss commented 3 years ago

登录切换到主窗口.zip

jcyrss commented 3 years ago

accounts.xlsx

lessons.zip

jcyrss commented 2 years ago

image