Last active
November 28, 2024 19:15
-
-
Save ungeskriptet/b774ef9e02f4a0ee58a7e3bad14d2eea to your computer and use it in GitHub Desktop.
Get solutions for a LearningApp on learningapps.org. Not all app types are supported. (Code explained: https://youtu.be/3K3MMtoG8rY)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import json | |
import requests | |
import sys | |
from urllib.parse import unquote | |
# Usage: python unlearningapps.py <ID> | |
# You can get the ID from the URL or | |
# by observing the network tab in your | |
# browser if it is embedded | |
url = sys.argv[1] | |
with requests.get(f'https://learningapps.org/data', params={'id': url}) as data: | |
data = unquote(json.loads(data.text)['initparameters']) | |
right = {} | |
answers = {} | |
if data.startswith('question1=text'): | |
attribute = True | |
for i in data.split('|'): | |
if i != '': | |
if attribute == True: | |
attribute = False | |
attrtext = i.split('&') | |
elif attribute == False: | |
attribute = True | |
for attrsplit in attrtext: | |
if 'right' in attrsplit: | |
rightsplit = attrsplit.split('_') | |
rightnum = rightsplit[0].split('right')[1] | |
if rightnum in right.keys(): | |
right[rightnum].append(rightsplit[1].split('=true')[0]) | |
else: | |
right[rightnum] = [rightsplit[1].split('=true')[0]] | |
elif 'question' in attrsplit or 'answer' in attrsplit: | |
answers[attrsplit] = i | |
for qnum, ansnums in right.items(): | |
try: | |
print(f'\033[94mQuestion {qnum}:\033[00m') | |
print(answers[f'question{qnum}=text']) | |
for ansnum in ansnums: | |
for line in answers[f'answer{qnum}_{ansnum}=text'].split('\n'): | |
print(' ', line) | |
except KeyError: | |
print(f'Could not find answer for question {qnum}') | |
if data.startswith('v1_1=text'): | |
for i in data.split('||'): | |
i = i.split('|') | |
for j in i[0].split('_'): | |
if '=text' in j: | |
cardnum = j.split('=text')[0] | |
if cardnum in answers.keys(): | |
answers[cardnum].append(i[1]) | |
else: | |
answers[cardnum] = [i[1]] | |
if cardnum: | |
for num, val in answers.items(): | |
print(f'\033[94mCard {num}:\033[00m') | |
for text in val: | |
print(' ', text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment