Exemple #1
0
def add_subject_ids():
    from wanikani_api.client import Client
    from kw_webapp.tasks import get_vocab_by_kanji

    client = Client("2510f001-fe9e-414c-ba19-ccf79af40060")
    subjects = client.subjects(fetch_all=True,
                               types="vocabulary",
                               hidden=False)
    total_subs = len(subjects)
    match_count = 0
    no_local_equivalent = []
    for subject in subjects:
        try:
            local_vocabulary = get_vocab_by_kanji(subject.characters)
            local_vocabulary.wk_subject_id = subject.id
            local_vocabulary.reconcile(subject)
            match_count += 1
            logger.info(
                f"{match_count} / {total_subs}:\t {subject.characters}")
        except Vocabulary.DoesNotExist:
            logger.warn(
                f"Found no local vocabulary with characters: {subject.characters}"
            )
            no_local_equivalent.append(subject)

    unmatched = Vocabulary.objects.filter(wk_subject_id=0)
    return unmatched, no_local_equivalent
Exemple #2
0
    def test_when_wanikani_changes_meaning_no_duplicate_is_created(self):
        resp_body = deepcopy(sample_api_responses.single_vocab_response)
        resp_body["requested_information"][0][
            "meaning"] = "NOT radioactive bat"

        # Mock response so that the level changes on our default vocab.
        mock_user_info_response(self.user.profile.api_key)
        responses.add(
            responses.GET,
            build_API_sync_string_for_user_for_levels(
                self.user, [self.user.profile.level]),
            json=resp_body,
            status=200,
            content_type="application/json",
        )

        Syncer.factory(self.user.profile).sync_with_wk()

        # Will fail if 2 vocab exist with same kanji.
        get_vocab_by_kanji("猫")
Exemple #3
0
    def test_when_wanikani_changes_meaning_no_duplicate_is_created(self):
        resp_body = deepcopy(sample_api_responses.single_vocab_response)
        resp_body['requested_information'][0]['meaning'] = "NOT radioactive bat"

        # Mock response so that the level changes on our default vocab.
        responses.add(responses.GET, build_API_sync_string_for_user_for_levels(self.user, [self.user.profile.level, ]),
                      json=resp_body,
                      status=200,
                      content_type='application/json')

        sync_unlocked_vocab_with_wk(self.user)

        # Will fail if 2 vocab exist with same kanji.
        vocabulary = get_vocab_by_kanji("猫")
Exemple #4
0
    def test_when_wanikani_changes_meaning_no_duplicate_is_created(self):
        resp_body = deepcopy(sample_api_responses.single_vocab_response)
        resp_body["requested_information"][0]["meaning"] = "NOT radioactive bat"

        # Mock response so that the level changes on our default vocab.
        responses.add(
            responses.GET,
            build_API_sync_string_for_user_for_levels(
                self.user, [self.user.profile.level]
            ),
            json=resp_body,
            status=200,
            content_type="application/json",
        )

        sync_unlocked_vocab_with_wk(self.user)

        # Will fail if 2 vocab exist with same kanji.
        vocabulary = get_vocab_by_kanji("猫")
Exemple #5
0
 def test_get_vocab_by_kanji_works_in_case_of_multiple_reading_vocab(self):
     v = create_vocab("my vocab")
     create_reading(v, "kana_1", "kanji", 5)
     create_reading(v, "kana_2", "kanji", 5)
     get_vocab_by_kanji("kanji")
 def test_get_vocab_by_kanji_works_in_case_of_multiple_reading_vocab(self):
     v = create_vocab("my vocab")
     create_reading(v, "kana_1", "kanji", 5)
     create_reading(v, "kana_2", "kanji", 5)
     get_vocab_by_kanji("kanji")