-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
174 lines (145 loc) · 5.98 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/python
# coding=utf-8
import argparse
import json
import os
import random
from library import library
var = {}
# use argparse to read command line
parser = argparse.ArgumentParser(description='A small, cross-platform program for NEIE.')
parser.add_argument('-s', '--path', type=str, help='path to server, may contain ip and port')
parser.add_argument('-u', '--username', type=str, help='username to login')
parser.add_argument('-p', '--password', type=str, help='password to login')
parser.add_argument('-t', '--type', type=str, help='rwt or vls')
parser.add_argument('-l', '--level', type=str, help='current level')
parser.add_argument('-ac', '--activation', help='try to activate user first', action='store_true')
parser.add_argument('-nf', '--no-file', help='stop read and write information to config.json', action='store_true')
parser.add_argument('--end-unit', help='stop at a unit before all unit learned')
parser.add_argument('--min-time', type=int, default=60, help='min time to learn a unit, default 60')
parser.add_argument('--max-time', type=int, default=120, help='max time to learn a unit, default 120')
parser.add_argument('--min-mark', type=int, default=80, help='min mark to learn a unit, default 80')
parser.add_argument('--max-mark', type=int, default=100, help='max mark to learn a unit, default 100')
args = parser.parse_args()
var['path'] = args.path
var['username'] = args.username
var['password'] = args.password
var['type'] = args.type
var['level'] = args.level
var['end-unit'] = args.end_unit
var['min-time'] = args.min_time
var['max-time'] = args.max_time
var['min-mark'] = args.min_mark
var['max-mark'] = args.max_mark
# sync information with config.json
if args.no_file == False:
config_file = os.getcwd() + '/config.json'
if os.path.isfile(config_file) == False:
with open(config_file, 'w+') as f:
pass
with open(config_file, 'r+') as f:
try:
obj = json.load(f)
except Exception as e:
print(e)
obj = {}
if input("Use previous config?(Y/n)") not in ['N','n']: # lazy option
def sync(var, obj, names):
for name in names:
try:
obj[name]
except:
obj[name] = None
if var[name] is None:
var[name] = obj[name]
elif var[name] != obj[name]:
var[name] = obj[name]
else:
def sync(var, obj, names):
for name in names:
try:
obj[name]
except:
obj[name] = None
if var[name] is None:
var[name] = obj[name]
elif var[name] != obj[name]:
obj[name] = var[name]
sync(var, obj, [name for name in var])
f.seek(0)
f.truncate() # discard the previous config or the file might go wrong
json.dump(obj, f)
# check necessary arguments
if var['path'] is None or var['username'] is None or var['password'] is None \
or var['type'] is None or var['level'] is None:
library.fail('missing required var')
exit()
# Var init
if var['type'] == 'rwt':
from rwt import *
learn = learn_rwt(var['path'], var['username'], var['password'], var['level'])
else:
from vls import *
learn = learn_vls(var['path'], var['username'], var['password'], var['level'])
# Activation
if args.activation == True:
print('Get Activation Code at http://www.neie.edu.cn/License/LicenseActivation.aspx')
SerialNumber = input('Serial Number: ')
LicenseNumber = input('License Number: ')
ActivationCode = input('Activation Code: ')
print('Confirm your information')
print('Path: ' + var['path'])
print('Username: ' + var['username'])
print('Level: ' + var['level'])
print('Serial Number: ' + SerialNumber)
print('License Number: ' + LicenseNumber)
print('Activation Code: ' + ActivationCode)
answer = input('Is above information all right? (y/n)')
if answer == 'Y' or answer == 'y':
SerialNumber = SerialNumber.replace(' ', '').replace('-', '')
LicenseNumber = LicenseNumber.replace(' ', '').replace('-', '')
ActivationCode = ActivationCode.replace(' ', '').replace('-', '')
active(learn, SerialNumber, LicenseNumber, ActivationCode)
else:
exit()
# Login
if args.activation == False:
status = login(learn)
# Get Progress
status = get_progress(learn)
if status == '1':
fetch = library.fetch(var['type'], learn.level, learn.SectionID)
if fetch['next']['unit'] != learn.UnitID:
update_unit(learn)
learn.UnitID = fetch['next']['unit']
learn.SectionID = fetch['next']['section']
# Learn English
while True:
learn.GetServerTime()
library.success('learning ' + var['type'] + ': unit ' + learn.UnitID + ', section ' + learn.SectionID)
library.timer(random.randint(var['min-time'], var['max-time']))
library.success('finished ' + var['type'] + ': unit ' + learn.UnitID + ', section ' + learn.SectionID)
fetch = library.fetch(var['type'], learn.level, learn.SectionID)
if fetch['problem'] == 0:
score = 0
else:
# Get int in next two var
min_problem = int(var['min-mark'] * fetch['problem'] / 100) + 1
max_problem = int(var['max-mark'] * fetch['problem'] / 100)
if min_problem > max_problem:
min_problem = max_problem
score = random.randint(min_problem, max_problem) * 100.0 / fetch['problem']
status = end_section(learn, score)
try:
fetch['next']
except:
# end of all section
status = update_unit(learn)
break
if fetch['next']['unit'] != learn.UnitID:
status = update_unit(learn)
if learn.UnitID == var['end-unit']:
break
learn.UnitID = fetch['next']['unit']
learn.SectionID = fetch['next']['section']
status = start_section(learn)