Files
fesmoo_perdoliq/__app__.py

97 lines
2.5 KiB
Python
Raw Normal View History

2018-05-11 18:45:45 +03:00
from main import Perdoliq
2018-05-05 01:57:11 +03:00
import configparser
import random
2018-04-30 00:42:47 +03:00
2018-05-05 01:57:11 +03:00
config = configparser.ConfigParser()
2018-05-11 18:44:38 +03:00
# just parse user input and make proper action
2018-05-05 01:57:11 +03:00
def act(q):
2018-05-11 18:44:38 +03:00
if (q == 'h') or (q == 'help'):
print('''
2018-05-05 01:57:11 +03:00
`list` - list all test
`resolve <Subj> <Test>`
''')
elif q == 'list':
list_all()
elif q[:7] == 'resolve':
2018-05-11 18:44:38 +03:00
# chance to override accuracy
global accuracy
accuracy_new = input('Accuracy level [%s]: ' % accuracy)
if accuracy_new != '':
try:
accuracy = int(accuracy_new)
except:
pass
# set delay if needed
is_delayed = input(
'Wait random time per question and auto commit? [y/N]: ')
if is_delayed == 'y' or is_delayed == 'Y':
is_delayed = True
else:
is_delayed = False
2018-05-05 01:57:11 +03:00
q = q.split(' ')
if len(q) != 3:
print('''Specify Subj number and Test number.
List it with `list` command
example:
resolve 4 1''')
return 1
2018-05-11 18:44:38 +03:00
app.resolve(int(q[1]), int(q[2]), accuracy, is_delayed=is_delayed)
2018-05-05 01:57:11 +03:00
def list_all():
i = 0
for subj in app.subjects:
print("[%s] %s" % (i, subj))
i += 1
j = 0
for test in app.subjects[subj]:
print("\t[%s] %s" % (j, test))
j += 1
2018-05-11 18:44:38 +03:00
# read config. in case of missing config create new one.
2018-05-05 01:57:11 +03:00
try:
config.read("creds.ini")
username = config['creds']['user']
password = config['creds']['pass']
2018-05-11 18:44:38 +03:00
accuracy = int(config['mics']['accuracy'])
2018-05-05 01:57:11 +03:00
except:
print("Couldn't find appropriate config file. Let's create new.")
print("Provide credentials for fesmu.ru/eport/eport/ below")
2018-05-11 18:44:38 +03:00
username = input('User ID %s ' % '>>>')
password = input('Password %s ' % '>>>')
2018-05-05 01:57:11 +03:00
config['creds'] = {}
config['creds']['user'] = username
config['creds']['pass'] = password
print("Also you are able to set desired level of accuracy in percent (%).")
2018-05-11 18:44:38 +03:00
accuracy = int(input('Accuracy %s ' % '>>>'))
2018-05-05 01:57:11 +03:00
while (accuracy < 0) or (accuracy > 100):
print("Are you stupid? Try again.")
2018-05-11 18:44:38 +03:00
accuracy = int(input('Accuracy %s ' % '>>>'))
2018-05-05 01:57:11 +03:00
config['mics'] = {}
config['mics']['accuracy'] = str(accuracy)
with open('creds.ini', 'w') as configfile:
config.write(configfile)
2018-04-30 00:42:47 +03:00
2018-05-11 18:45:45 +03:00
app = Perdoliq(username, password)
2018-04-30 00:42:47 +03:00
2018-05-11 18:44:38 +03:00
# make auth
2018-04-30 02:39:48 +03:00
app.auth()
2018-05-11 18:44:38 +03:00
# update tests
2018-04-30 02:39:48 +03:00
app.get_tests()
2018-05-05 01:57:11 +03:00
print('''
You are in bot command line engine.
Type h or help for help.
''')
while True:
2018-05-11 18:44:38 +03:00
q = input('Command %s ' % '>>>')
2018-05-05 01:57:11 +03:00
act(q)