Esempio n. 1
0
def one_time_merge_level(level, user=None):
    api_call = "https://www.wanikani.com/api/user/{}/vocabulary/{}".format(
        constants.API_KEY, level)
    response = make_api_call(api_call)
    vocab_list = response['requested_information']
    print("Vocab found:{}".format(len(vocab_list)))

    for vocabulary_json in vocab_list:
        print("**************************************************************")
        print("Analyzing vocab with kanji:[{}]\tCanonical meaning is:[{}]".
              format(vocabulary_json['character'], vocabulary_json['meaning']))
        found_vocabulary = Vocabulary.objects.filter(
            readings__character=vocabulary_json['character'])
        print("found [{}] vocabulary on the server with kanji [{}]".format(
            found_vocabulary.count(), vocabulary_json['character']))
        if found_vocabulary.count(
        ) == 1 and found_vocabulary[0].meaning == vocabulary_json['meaning']:
            print(
                "No conflict found. Precisely 1 vocab on server, and meaning matches."
            )
        elif found_vocabulary.count() > 1:
            print(
                "Conflict found. Precisely [{}] vocab on server for meaning [{}]."
                .format(found_vocabulary.count(), vocabulary_json['meaning']))
            handle_merger(vocabulary_json, found_vocabulary)
        elif found_vocabulary.count() == 0:
            create_new_vocabulary(vocabulary_json)
        else:
            print("No conflict, but meaning has changed. Changing meaning!")
            to_be_edited = found_vocabulary[0]
            to_be_edited.meaning = vocabulary_json['meaning']
            to_be_edited.save()
Esempio n. 2
0
def handle_merger(vocabulary_json, found_vocabulary):
    ids_to_delete = found_vocabulary.values_list('id', flat=True)
    ids_to_delete_list = list(ids_to_delete)
    vocabulary = create_new_vocabulary(vocabulary_json)
    create_new_review_and_merge_existing(vocabulary, found_vocabulary)
    Vocabulary.objects.filter(pk__in=ids_to_delete_list).exclude(
        id=vocabulary.id).delete()
Esempio n. 3
0
File: utils.py Progetto: tadgh/KW
def handle_merger(vocabulary_json, found_vocabulary):
    ids_to_delete = found_vocabulary.values_list("id", flat=True)
    ids_to_delete_list = list(ids_to_delete)
    vocabulary = create_new_vocabulary(vocabulary_json)
    create_new_review_and_merge_existing(vocabulary, found_vocabulary)
    Vocabulary.objects.filter(pk__in=ids_to_delete_list).exclude(
        id=vocabulary.id
    ).delete()
Esempio n. 4
0
File: utils.py Progetto: tadgh/KW
def one_time_merge_level(level, user=None):
    api_call = "https://www.wanikani.com/api/user/{}/vocabulary/{}".format(
        constants.API_KEY, level
    )
    response = make_api_call(api_call)
    vocab_list = response["requested_information"]
    print("Vocab found:{}".format(len(vocab_list)))

    for vocabulary_json in vocab_list:
        print("**************************************************************")
        print(
            "Analyzing vocab with kanji:[{}]\tCanonical meaning is:[{}]".format(
                vocabulary_json["character"], vocabulary_json["meaning"]
            )
        )
        found_vocabulary = Vocabulary.objects.filter(
            readings__character=vocabulary_json["character"]
        )
        print(
            "found [{}] vocabulary on the server with kanji [{}]".format(
                found_vocabulary.count(), vocabulary_json["character"]
            )
        )
        if (
            found_vocabulary.count() == 1
            and found_vocabulary[0].meaning == vocabulary_json["meaning"]
        ):
            print(
                "No conflict found. Precisely 1 vocab on server, and meaning matches."
            )
        elif found_vocabulary.count() > 1:
            print(
                "Conflict found. Precisely [{}] vocab on server for meaning [{}].".format(
                    found_vocabulary.count(), vocabulary_json["meaning"]
                )
            )
            handle_merger(vocabulary_json, found_vocabulary)
        elif found_vocabulary.count() == 0:
            create_new_vocabulary(vocabulary_json)
        else:
            print("No conflict, but meaning has changed. Changing meaning!")
            to_be_edited = found_vocabulary[0]
            to_be_edited.meaning = vocabulary_json["meaning"]
            to_be_edited.save()
Esempio n. 5
0
 def test_create_new_vocab_based_on_json_works(self):
     vocab = create_new_vocabulary(single_vocab_requested_information)
     self.assertIsInstance(vocab, Vocabulary)
Esempio n. 6
0
 def test_create_new_vocab_based_on_json_works(self):
     vocab = create_new_vocabulary(single_vocab_requested_information)
     self.assertIsInstance(vocab, Vocabulary)