Skip to content

Commit

Permalink
Add save_words_task
Browse files Browse the repository at this point in the history
  • Loading branch information
kimdoori committed Apr 30, 2020
1 parent fe82edf commit c3e862b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion word_way/scrapping/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@
from word_way.models import Pronunciation, Sentence, Word, WordSentenceAssoc
from word_way.utils import convert_word_part

__all__ = 'save_word', 'save_word_task',
__all__ = 'save_word', 'save_word_task', 'save_words_task',


@celery.task
def save_word_task(target_word: str):
save_word(target_word, session)


@celery.task
def save_words_task():
"""단어가 없는 발음을 가져와서 단어를 저장하는 테스크"""
q = session.query(Word).filter(Word.pronunciation_id == Pronunciation.id)
pronunciations = session.query(Pronunciation).filter(
~q.exists()
).all()
for pronunciation in pronunciations:
pronunciation_id = save_word(pronunciation.pronunciation, session)
if not pronunciation_id:
session.delete(pronunciation)
session.commit()


def save_word(
target_word: str, session: Session,
) -> typing.Optional[uuid.UUID]:
Expand Down

0 comments on commit c3e862b

Please sign in to comment.