60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import json
|
|
import sys
|
|
from getpass import getpass
|
|
|
|
from codeforces.client.client import CodeforcesClient
|
|
from codeforces.client.spinner import Spinner
|
|
from codeforces.ui.utils import CONFIG_FILE, SESSION_FILE, get_int
|
|
|
|
|
|
def add_login_data():
|
|
login = input("Login: ")
|
|
password = getpass("Password: ")
|
|
|
|
with Spinner("Logging in (this may take a long time)..."):
|
|
c = CodeforcesClient.auth(login, password)
|
|
|
|
with open(SESSION_FILE, 'w') as f:
|
|
json.dump({
|
|
'login': login,
|
|
'password': password,
|
|
'session': c.to_dict()
|
|
}, f)
|
|
|
|
|
|
def add_template():
|
|
template_path = input('Path to the template file (i.e. ~/algo_template.cpp): ')
|
|
try:
|
|
with open(template_path) as f:
|
|
template = f.read()
|
|
with open(CONFIG_FILE) as f:
|
|
config = json.load(f)
|
|
config.update({'template': template})
|
|
with open(CONFIG_FILE, 'w') as f:
|
|
json.dump(config, f)
|
|
except Exception:
|
|
print("Invalid path!", file=sys.stderr)
|
|
return add_template()
|
|
|
|
print("Added successfuly!", end='\n\n')
|
|
|
|
|
|
def config_menu():
|
|
print('CFTool-Reborn configuration menu. Press <C-c> to exit.', end='\n\n')
|
|
|
|
options = [
|
|
'1) Add/Update login data',
|
|
'2) Add a template'
|
|
]
|
|
|
|
try:
|
|
while True:
|
|
ans = get_int(options)
|
|
if ans == 0:
|
|
return
|
|
elif ans == 1:
|
|
add_login_data()
|
|
elif ans == 2:
|
|
add_template()
|
|
except KeyboardInterrupt:
|
|
return
|