Skip to content

Commit

Permalink
fix import programs script because now program requires login
Browse files Browse the repository at this point in the history
  • Loading branch information
bojieli committed Jul 13, 2024
1 parent 600e72b commit ba397d1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/import_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
domain = 'catalog.ustc.edu.cn'
site_root = 'https://' + domain + '/'

if len(sys.argv) != 2:
print("Usage: Please login to catalog.ustc.edu.cn and get the cookie, then run 'python3" + sys.argv[0] + " <cookie>'")
sys.exit(-1)
cookie = sys.argv[1]
if cookie.startswith('Cookie:'):
cookie = cookie[len('Cookie:'):].strip()

headers = {
'accept': 'application/json, text/javascript, */*; q=0.01',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
'authority': domain,
'cookie': cookie,
'referer': site_root + 'plan'
}

# get access token
token_json = requests.get(site_root + 'get_token', headers=headers)
access_token = json.loads(token_json.text)['access_token']

# load existing data
with app.app_context():
existing_majors = Major.query.all()
Expand Down Expand Up @@ -119,15 +123,14 @@ def load_program_recursive(program_id, tree):

def load_program(program_id):
url = site_root + 'api/teach/program/info/' + str(program_id)
param = 'access_token=' + access_token
tree_json = requests.get(url + '?' + param, headers=headers)
tree_json = requests.get(url, headers=headers)
tree = json.loads(tree_json.text)
module_tree = tree['moduleTree']
return load_program_recursive(program_id, module_tree)


def load_tree():
tree_json = requests.get(site_root + 'api/teach/program/tree?access_token=' + access_token, headers=headers)
tree_json = requests.get(site_root + 'api/teach/program/tree', headers=headers)
tree = json.loads(tree_json.text)

for json_dept_id in tree:
Expand Down

0 comments on commit ba397d1

Please # to comment.