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

格式化代码

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