Skip to content

Commit

Permalink
Merge pull request #7 from greatericontop/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Gerseneck authored Oct 12, 2023
2 parents cc75eb3 + e09f2d6 commit 74ec242
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 106 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ You can set a custom API key in the config (go to `options`, then `API keys`) to

---

## Quizlet Convert

Quizlet sets can convert to GreatStudier using the `Quizlet Convert` Option in the menu. The Quizlet set must be public to be able to be converted.

---

## Options

`set_directory` >> The directory that the sets are stored in. Defaults to `~/GreatStudier`.
Expand All @@ -76,6 +70,8 @@ Quizlet sets can convert to GreatStudier using the `Quizlet Convert` Option in t

`alpha_only` >> Removes any non-alphanumeric characters (punctuation, unicode, etc.) from answers.

`answer_with` >> Choose to answer with `TERM` or `DEFINITION`.

---

## License
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def update_with_defaults(original_config: dict = None) -> dict:
original_config['uploaded_set_permission'] = 'unlisted'
if 'alpha_only' not in original_config:
original_config['alpha_only'] = False
if 'answer_with' not in original_config:
original_config['answer_with'] = 0
return original_config


Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


VERSION = '1.3.1'
VERSION = '1.4.0'


class C:
Expand Down
36 changes: 23 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import quiz
import uploads
import utils
from quizlet_convert import convert_quizlet_set
from set_manager import choose_set, new_set, edit_mode
from constants import *

Expand Down Expand Up @@ -63,9 +62,14 @@ def learn(words, new_terms) -> None:
study_indices = list(range(amount))
for i in study_indices:
key = new_terms[i]
print(f'\n\n{C.yellow}{key.word} {C.green}= {C.darkyellow}{key.definition}{C.end}')
question = key.definition
answer = key.word
if utils.answer_mode(config.config['answer_with']) == utils.answer_mode.DEFINITION:
question = key.word
answer = key.definition
print(f'\n\n{C.yellow}{answer} {C.green}= {C.darkyellow}{question}{C.end}')
while True:
if input().strip().lower() == key.word.lower():
if input().strip().lower() == answer.lower():
break
print(f'{CLEAR}Ready for the quiz?')
quiz_number = 0
Expand All @@ -81,6 +85,7 @@ def learn(words, new_terms) -> None:
utils.save_words(words, config.config['set'])
print('You are done!')
gamify.increment_login_bonus()
gamify.gamify_data['xp'] += 20 if amount == NEW_CHUNK_SIZE else 10 # session bonus
input(CONTINUE)
print(CLEAR)

Expand All @@ -101,6 +106,7 @@ def review(words, review_terms) -> None:
utils.save_words(words, config.config['set'])
print('You are done!')
gamify.increment_login_bonus()
gamify.gamify_data['xp'] += 45 if amount == REVIEW_CHUNK_SIZE else 25 # session bonus
input(CONTINUE)
print(CLEAR)

Expand All @@ -119,6 +125,7 @@ def study(words) -> None:
quiz.quiz(word, extra=f'#{i + 1}/{total} ', increment_knowledge_level=False)
print('You are done!')
gamify.increment_login_bonus()
gamify.gamify_data['xp'] += 20 if total >= 10 else 5 # session bonus
input(CONTINUE)
print(CLEAR)

Expand Down Expand Up @@ -218,6 +225,8 @@ def open_settings() -> None:
continue
if key == 'paste_api_key' and value is not None:
value = value[:4] + '**********'
if key == 'answer_with' and value is not None:
value = utils.answer_mode(value).name
# distinguish between the actual None and a string called that
if value is None:
value = '<None>'
Expand All @@ -233,6 +242,11 @@ def open_settings() -> None:
if settings_change == 'reset':
if input('Do you really want to reset the config? [Y/n]: ') in YES_DEFAULT_YES:
config.config = config.update_with_defaults()
elif settings_change == 'answer_with':
if config.config[settings_change] is None:
config.config[settings_change] = 0
config.config[settings_change] = (config.config[settings_change] + 1) % 2
print(f'Value set to {C.bwhite}{utils.answer_mode(config.config[settings_change]).name}{C.end}.\n')
elif settings_change not in config.config:
print(f'{C.red}That is not a valid option.{C.end}\n')
elif type(config.config[settings_change]) is bool:
Expand Down Expand Up @@ -265,18 +279,16 @@ def main():
learning_available = False
prompt = (f'{C.darkred}It seems you do not have a set chosen!{C.end}\n'
f'{C.no}[L]earn{C.end} {C.no}[R]eview{C.end} {C.no}[S]tudy{C.end}\n'
f'{C.no}[U]pload Set{C.end} [D]ownload Set [Qu]izlet Convert\n'
f'[C]hoose Set [N]ew Set {C.no}[M]odify Set{C.end}\n'
f'[O]ptions [St]ats {C.no}[W]ipe Progress{C.end}\n'
f'[Q]uit\n'
f'{C.no}[U]pload Set{C.end} [D]ownload Set [C]hoose Set\n'
f'[N]ew Set {C.no}[M]odify Set{C.end} [O]ptions\n'
f'[St]ats {C.no}[W]ipe Progress{C.end} [Q]uit\n'
f'{C.darkblue}>{C.end} ')
else:
learning_available = True
prompt = (f'[L]earn [R]eview [S]tudy\n'
f'[U]pload Set [D]ownload Set [Qu]izlet Convert\n'
f'[C]hoose Set [N]ew Set [M]odify Set\n'
f'[O]ptions [St]ats [W]ipe Progress\n'
f'[Q]uit\n'
f'[U]pload Set [D]ownload Set [C]hoose Set\n'
f'[N]ew Set [M]odify Set [O]ptions\n'
f'[St]ats [W]ipe Progress [Q]uit\n'
f'{C.darkblue}>{C.end} ')
word_set = config.config['set']
words = utils.load_words(word_set)
Expand Down Expand Up @@ -304,8 +316,6 @@ def main():
# end learning available
elif cmd in {'download', 'd'}:
download_set()
elif cmd in {'quizlet', 'qu'}:
convert_quizlet_set()
elif cmd in {'choose', 'c'}:
choose_set()
elif cmd in {'new', 'n'}:
Expand Down
18 changes: 14 additions & 4 deletions quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import time
from typing import TYPE_CHECKING

import config
import gamify
import utils
from constants import *
Expand All @@ -43,11 +44,20 @@ def correct_answer_study(key: KeyData):

def quiz(key: KeyData, extra: str = '', increment_knowledge_level: bool = True) -> bool:
on_correct = correct_answer_increment_knowledge if increment_knowledge_level else correct_answer_study
print(f'\n\n{extra}QUIZ: What is {C.cyan}{key.definition}{C.end}?')

# default
question = key.definition
answer = key.word

if utils.answer_mode(config.config['answer_with']) == utils.answer_mode.DEFINITION:
question = key.word
answer = key.definition

print(f'\n\n{extra}QUIZ: What is {C.cyan}{question}{C.end}?')
gamify.start_study_clock()
guess = input(f'{C.darkblue}>{C.end} ')
gamify.end_study_clock()
result = utils.validate(guess, key.word)
result = utils.validate(guess, answer)
gamify.increment_study()

if result == utils.ValidationResult.FULL_CORRECT:
Expand All @@ -57,7 +67,7 @@ def quiz(key: KeyData, extra: str = '', increment_knowledge_level: bool = True)
return True

elif result == utils.ValidationResult.MOSTLY_CORRECT:
print(f'{C.darkgreen}Mostly correct! It actually was: {C.white}{key.word}{C.end}')
print(f'{C.darkgreen}Mostly correct! It actually was: {C.white}{answer}{C.end}')
if input() != '*':
on_correct(key)
return True
Expand All @@ -68,7 +78,7 @@ def quiz(key: KeyData, extra: str = '', increment_knowledge_level: bool = True)
return False

else:
print(f"{C.red}Sorry, that's incorrect! It actually was: {C.white}{key.word}{C.end}")
print(f"{C.red}Sorry, that's incorrect! It actually was: {C.white}{answer}{C.end}")
if input() == '*':
print(f'You have overwritten your answer to {C.green}CORRECT{C.end}')
on_correct(key)
Expand Down
81 changes: 0 additions & 81 deletions quizlet_convert.py

This file was deleted.

5 changes: 4 additions & 1 deletion set_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def edit_mode(words) -> None:
consent = input(f'Are you sure you want to delete this set? \'{config.config["set"]}\' will be lost forever (A long time!) [Y/n] ')
if consent in YES_DEFAULT_YES:
set_path = config.get_set_directory() / config.config['set']
delete_path = config.get_set_directory() / '.trash' / config.config['set']
trash_folder = config.get_set_directory() / '.trash'
if not trash_folder.exists():
trash_folder.mkdir()
delete_path = trash_folder / config.config['set']
set_path.rename(delete_path)
config.config['set'] = None
print(CLEAR)
Expand Down
5 changes: 5 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class KeyData:
repetition_spot: int


class answer_mode(enum.Enum):
TERM = 0
DEFINITION = 1


def file_check(contents: list[str]) -> bool:
return contents[0].lower().startswith('## * greatstudier *')

Expand Down

0 comments on commit 74ec242

Please sign in to comment.