Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DedInc committed Nov 1, 2022
1 parent 9f7a28f commit a283a6c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
13 changes: 8 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ category = getCategoryByName('Add') # Get Addition by Name
problems = generateProblems(count=10, lvl=0, type=category)
problem = choice(problems) # Get random problem

print(problem['problem']['text']) # Text of the problem
print(problem['problem']['image']) # Image of the problem

print(problem['hint']) # Image of the hint
print(problem['solution']) # Image of the solution
print(problem['text']) # Text of the problem
print(problem['image']) # Image of the problem
print(problem['difficulty']) # Difficulty of the problem

c = checkProblem(problem, 'x+5') # Check problem, where x+5 - answer
print(c['correct']) # True or False
print(c['hint']) # Image of the Hint
print(c['solution']) # Image of the Solution
```
2 changes: 1 addition & 1 deletion problemator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .problemator import loadSession, getCategories, getCategoryByID, getCategoryByName, generateProblems
from .problemator import loadSession, getCategories, getCategoryByID, getCategoryByName, generateProblems, checkProblem
15 changes: 9 additions & 6 deletions problemator/problemator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ def loadSession():
API = s.get('https://www.wolframalpha.com/input/wpg/categories.jsp?load=true').json()['domain']


def checkProblem(problem, answer):
lvl = problem['difficulty']
pid = problem['id']
machine = problem['machine']
r = s.get(f'{API}/input/wpg/checkanswer.jsp?attempt=1&difficulty={lvl}&load=true&problemID={pid}&query={answer}&s={machine}&type=InputField').json()
return {'correct': r['correct'], 'hint': r['hint'], 'solution': r['solution']}


def generateProblems(lvl=0, type='IntegerAddition', count=1):
lvl = {0: 'Beginner', 1: 'Intermediate', 2: 'Advanced'}[lvl]
r = s.get(f'{API}/input/wpg/problem.jsp?count={count}&difficulty={lvl}&load=1&type={type}').json()
problems = r['problems']
machine = r['machine']
arr = []
for problem in problems:
pid = problem['problem_id']
r = s.get(f'https://www6b3.wolframalpha.com/input/wpg/checkanswer.jsp?attempt=1&difficulty={lvl}&load=true&problemID={pid}&query=const&s={machine}&type=InputField').json()
arr.append({'problem': {'text': problem['string_question'], 'image': problem['problem_image']}, 'hint': r['hint'], 'solution': r['solution']})
return arr
return [{'text': problem['string_question'], 'image': problem['problem_image'], 'difficulty': lvl, 'id': problem['problem_id'], 'machine': machine} for problem in problems]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="problemator",
version="1.0.2",
version="1.0.3",
author="Maehdakvan",
author_email="visitanimation@google.com",
description="WolframAlpha's Unlimited AI-generated practice problems and answers API wrapper.",
Expand Down

0 comments on commit a283a6c

Please sign in to comment.