Commit 06459e07 authored by 曹高翔's avatar 曹高翔
Browse files

格式化代码

parent 92e5ae5e
......@@ -14,6 +14,7 @@ variables = {
from os import environ, path, makedirs
from sys import platform
if platform == 'darwin':
variables['appDataPath'] = "~/Library/codiaclient"
elif platform == 'win32':
......@@ -22,6 +23,7 @@ if not path.exists(variables['appDataPath']):
makedirs(variables['appDataPath'])
variables['sessionPath'] = path.join(variables['appDataPath'], ".cache")
def cache_for_login(userdic, passwd, cookie=None, passwd_store_on=0):
file = variables['sessionPath']
if not variables['cache_on']:
......
......@@ -43,6 +43,7 @@ login_base_headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46',
}
def post(url, headers, data, timeout=5):
headers['content-length'] = str(len(data))
if type(data) == str: data = data.encode('utf-8')
......@@ -64,6 +65,7 @@ def post(url, headers, data, timeout=5):
else:
return res
def client_login(args=None, username=None, password=None, cookie=None):
if args:
username = args.username
......@@ -154,6 +156,7 @@ def client_login(args=None, username=None, password=None, cookie=None):
else:
report('No username or cookie specified.', 3)
def logined(reportUnverified: bool = True):
headers = coding_base_headers.copy()
data = json.dumps({
......@@ -192,6 +195,7 @@ def logined(reportUnverified: bool = True):
return "UNMATCHED", res_data['data']['me']['displayName']
return "SUCCESS", res_data['data']['me']['displayName']
def login(username, passwd):
report('Try login.')
res = _login(username, passwd)
......@@ -202,6 +206,7 @@ def login(username, passwd):
report('Login succeeded.({})'.format(res['displayName']))
return True
def register(username, passwd, email=None):
headers = login_base_headers.copy()
if not email: email = input("Input your email:")
......@@ -236,6 +241,7 @@ mutation signup($login: String!, $password: String!, $email: String!) {
return False
return res_data['data']['signup']['user']
def change_password(identifier=None, vercode=None, passwd=None, passwordconfirm=None):
import getpass
headers = login_base_headers.copy()
......@@ -317,6 +323,7 @@ mutation passwordChange($newPassword: String!, $verifyToken: String) {
return False
return passwd
def _acquire_verification(identifier=None):
headers = login_base_headers.copy()
if not identifier: identifier = input("Input your email/phone:")
......@@ -357,12 +364,14 @@ mutation acquireVerification($identifier: String!, $type: VerificationType!) {
return None, False
return identifier, res_data['data']['acquireVerification']
def submit(eid, pid, lang, solutioncode):
if pid:
return _submit_from_pack(eid, pid, lang, solutioncode)
else:
return _submit_not_from_pack(eid, lang, solutioncode)
def get_data(eid, pid, before=None, after=None, cnt=None):
if not cnt:
if pid:
......@@ -384,12 +393,14 @@ def get_data(eid, pid, before=None, after=None, cnt=None):
res.reverse()
return res
def get_exercise(eid, pid, lang, feedback='dict'):
if pid:
return _get_exercise_from_pack(eid, pid, lang, feedback)
else:
return _get_exercise_not_from_pack(eid, lang, feedback)
def get_pack(before=None, after=None, cnt=None):
if cnt == None: cnt = 8
if type(cnt) == str:
......@@ -454,6 +465,7 @@ query publicExercisePacks({queryargs}) {{
except:
return False
def show_pack(pid):
headers = coding_base_headers.copy()
data = json.dumps({
......@@ -491,6 +503,7 @@ query pack($pid: ID!) {
if not res: return False
return json.loads(res.text)['data']['node']
def start_pack(pid):
if show_pack(pid)['viewerStatus']['ongoing']:
report("This pack is already ongoing.", 1)
......@@ -539,6 +552,7 @@ mutation startSession($pid: ID!, $code: String) {
except:
return False
def _login(username, passwd):
headers = login_base_headers.copy()
data = json.dumps({
......@@ -578,6 +592,7 @@ mutation login($username: String!, $password: String!) {
cookie=coding_base_headers['cookie'], passwd_store_on=variables['passwd_store_on'])
return res_data['data']['login']['user']
def _submit_from_pack(eid, pid, lang, solutioncode):
headers = coding_base_headers.copy()
data = json.dumps({
......@@ -601,6 +616,7 @@ mutation ($eid: ID!, $pid: ID, $lang: Language!, $sol: String!, $a: JSONObject)
if not res: return False
return json.loads(res.text)
def _submit_not_from_pack(eid, lang, solutioncode):
headers = coding_base_headers.copy()
data = json.dumps({
......@@ -623,6 +639,7 @@ mutation ($eid: ID!, $pid: ID, $lang: Language!, $sol: String!, $a: JSONObject)
if not res: return False
return json.loads(res.text)
def _get_data_not_from_pack(eid, before=None, after=None, cnt=None):
if cnt == None: cnt = 1
if type(cnt) == str:
......@@ -693,6 +710,7 @@ query codingExercise({queryargs}) {{
except:
return False
def _get_data_from_pack(eid, pid, before=None, after=None, cnt=None):
if cnt == None: cnt = 1
if type(cnt) == str:
......@@ -772,6 +790,7 @@ query codingExercise({queryargs}) {{
except:
return False
def _get_exercise_not_from_pack(eid, lang, feedback='dict'):
headers = coding_base_headers.copy()
data = json.dumps({
......@@ -861,6 +880,7 @@ query codingExercise($eid: ID!, $lang: Language!) {
else:
return None
def _get_exercise_from_pack(eid, pid, lang, feedback='dict'):
headers = coding_base_headers.copy()
data = json.dumps({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment