|
| 1 | +# coding=utf-8 |
| 2 | +## |
| 3 | +# brief 选择模式启动刷课 |
| 4 | +# details 先后读取logindata_phone.txt(2行一个账号)和logindata.txt(3行一个账号)的全部账号信息 |
| 5 | +# windows环境下:对于每一份账号信息启动一个cmd命令行来执行刷课操作 |
| 6 | +# Linux(docker)环境下:待定 |
| 7 | +# author Luoofan |
| 8 | +# date 2020-03-27 20:38:15 |
| 9 | +# FilePath\source_codes\autocx.py |
| 10 | +# |
| 11 | +from subprocess import Popen |
| 12 | +from time import sleep |
| 13 | +from colorama import Fore |
| 14 | +from colorama import init as colorinit |
| 15 | +from sys import argv |
| 16 | +from getopt import gnu_getopt |
| 17 | +from requests import post |
| 18 | +from platform import platform,architecture |
| 19 | + |
| 20 | +class Color(object): |
| 21 | + END = Fore.RESET |
| 22 | + OK = Fore.GREEN |
| 23 | + NOTE = Fore.YELLOW |
| 24 | + WARN = Fore.MAGENTA |
| 25 | + ERR = Fore.RED |
| 26 | + DISPLAY = Fore.BLUE |
| 27 | + |
| 28 | + instance =None |
| 29 | + |
| 30 | + def __new__(cls,*args,**kwargs): |
| 31 | + if cls.instance is None: |
| 32 | + cls.instance=super().__new__(cls) |
| 33 | + return cls.instance |
| 34 | + |
| 35 | + def __init__(self): |
| 36 | + colorinit() |
| 37 | + #print(self) |
| 38 | + |
| 39 | +COLOR = Color() |
| 40 | + |
| 41 | +def getlogindata(): |
| 42 | + return open(r'./logindata.txt', 'r', encoding='utf-8').readlines() |
| 43 | + |
| 44 | +def getlogindata_phone(): |
| 45 | + return open(r'./logindata_phone.txt', 'r', encoding='utf-8').readlines() |
| 46 | + |
| 47 | +def send_err(err_info): |
| 48 | + data = { |
| 49 | + 'platform': platform(), |
| 50 | + 'arch': str(architecture()), |
| 51 | + 'errorinfo': err_info |
| 52 | + } |
| 53 | + post('http://39.98.127.46/index.php', data=data) |
| 54 | + |
| 55 | +def perform(mode,rate): |
| 56 | + #处理账号信息 |
| 57 | + print(COLOR.DISPLAY+'Welcome To Multi-Autocx!'+COLOR.END) |
| 58 | + |
| 59 | + # 读取 手机号+密码 弹出多个弹窗 |
| 60 | + lt_phone = getlogindata_phone() |
| 61 | + for i in range(len(lt_phone)//2): |
| 62 | + logindata = "" |
| 63 | + try: |
| 64 | + for j in range(i*2, (i+1)*2): |
| 65 | + logindata += (lt_phone[j].strip(' \n'))+',' |
| 66 | + except IndexError: |
| 67 | + print(' Sorry,no info') |
| 68 | + break |
| 69 | + # print(logindata) |
| 70 | + Popen('start cmd /k python login_courses.py '+logindata[0:-1]+' '+str(mode)+' '+str(rate), shell=True) |
| 71 | + sleep(2) |
| 72 | + |
| 73 | + # 读取 机构账号 需要输入验证码 每次处理一个 按任意键后处理下一个 |
| 74 | + lt = getlogindata() |
| 75 | + for i in range(len(lt)//3): |
| 76 | + logindata = "" |
| 77 | + try: |
| 78 | + for j in range(i*3, (i+1)*3): |
| 79 | + logindata += (lt[j].strip(' \n'))+',' |
| 80 | + except IndexError: |
| 81 | + print(' Sorry,no info') |
| 82 | + break |
| 83 | + # print(logindata) |
| 84 | + Popen('start cmd /k python login_courses.py '+logindata[0:-1]+' '+str(mode)+' '+str(rate), shell=True) |
| 85 | + input(COLOR.OK+' please press any key to continue'+COLOR.END) |
| 86 | + |
| 87 | + print(COLOR.DISPLAY+'Now you can exit this program! Good luck!'+COLOR.END) |
| 88 | + |
| 89 | +def main(): |
| 90 | + #参数处理 |
| 91 | + try: |
| 92 | + opts,args=gnu_getopt(argv[1:],'-m:-r:-v-h',['mode=','rate=','version','help']) |
| 93 | + except: |
| 94 | + print(COLOR.ERR+'Invalid args, Try -h or --help for more information'+COLOR.END) |
| 95 | + exit() |
| 96 | + #print(opts) |
| 97 | + #print(args) |
| 98 | + rate=1 |
| 99 | + mode="single" |
| 100 | + opt_mode = ['single', 'fullauto', 'control'] |
| 101 | + for opt_name,opt_value in opts: |
| 102 | + if opt_name in ('-h','--help'): |
| 103 | + print(''' |
| 104 | +-m(--mode) single 单课程自动模式: 选择课程,自动完成该课程(默认启动参数) |
| 105 | + fullauto 全自动模式: 自动遍历全部课程,无需输入(除了机构登录方式下需要输入验证码) |
| 106 | + control 单课程控制模式: 选择课程并选择控制章节,自动完成[该课程第一个未完成章节,选定章节)范围内章节 |
| 107 | +-r(--rate) [0.625,16] 全局倍速设置: 在选定模式的全局范围内开启该倍速 |
| 108 | +-h(--help) usage |
| 109 | +-v(--version) version |
| 110 | + ''') |
| 111 | + exit() |
| 112 | + if opt_name in ('-v','--version'): |
| 113 | + print('2.0beta') |
| 114 | + exit() |
| 115 | + if opt_name in ('-r','--rate'): |
| 116 | + rate=eval(opt_value) |
| 117 | + if rate>16 or rate<0.625: |
| 118 | + print(COLOR.ERR+'Invalid rate range, Try -h or --help for more information'+COLOR.END) |
| 119 | + exit() |
| 120 | + if opt_name in ('-m','--mode'): |
| 121 | + mode=opt_value |
| 122 | + if mode not in opt_mode: |
| 123 | + print(COLOR.ERR+'Invalid args, Try -h or --help for more information'+COLOR.END) |
| 124 | + exit() |
| 125 | + #调用 执行 mode & rate |
| 126 | + print(COLOR.DISPLAY+'Set the mode: %s and the rate: %.2f'%(mode,rate)+COLOR.END) |
| 127 | + perform(opt_mode.index(mode),rate) |
| 128 | + |
| 129 | +if __name__=='__main__': |
| 130 | + main() |
0 commit comments