Ejemplo n.º 1
0
 def study(self, ):
     item = None
     while True:
         if not item:
             item = self.next()
         if not item:
             break
         command = self.study_one(item)
         if command == status.PLAY:
             continue
         if command == status.PARA:
             self.para(item)
             continue
         if command == status.EXIT:
             exit(0)
         if command == status.SKIP:
             self.skip(item)
             item = None
             continue
         if command == status.RIGHT:
             self.right(item)
             item = None
             functions.getch()
             continue
         if command == status.ERROR:
             self.error(item)
             pass
Ejemplo n.º 2
0
 def operate_review(self, word):
     if word.review.first():
         functions.getch()
         return
     action = functions.input(
         self.style.WARNING("Save to review (yes)?"))[0]
     if action not in ("yes", "YES", "y", "Y"):
         return
     functions.set_review(word)
     print(self.style.SUCCESS("Save to review success."))
     functions.getch()
Ejemplo n.º 3
0
    def study_one(self, item):
        if isinstance(item, models.Review):
            word = item.word
        elif isinstance(item, models.Word):
            word = item
        dandan.system.clear()
        self.play(word)
        titles = functions.input(" ")

        action = titles[0]
        if not action:
            return status.PLAY
        if action in {'e', 'exit'}:
            return status.EXIT
        if action in {
                'n',
        }:
            return status.SKIP
        if action in {'para', 'p', "trans", "t"}:
            self.print_paras(word)
            functions.getch()
            return status.PARA

        print(settings.SPLITTER)

        data = study.check(word, titles)

        for item in data.list:
            if item.error:
                print(styles.ERROR(item.title, True))
                continue
            if item.equal:
                print(styles.EQUAL(item.title, True))
                self.print_paras(word)
                continue
            if item.right:
                print(styles.RIGHT(item.title, True))
                self.print_paras(word)
                continue
            if item.exists:
                print(styles.EXIST(item.title, True))
                self.print_paras(functions.get_word(item.title))

        if data.error:
            self.practice(word)
            return status.ERROR
        return status.RIGHT
Ejemplo n.º 4
0
 def operate_result(self, title):
     result = youdao.get_word(title)
     if not result:
         print("Search not found '{}'".format(title))
         functions.getch()
         return
     functions.prints(result)
     action = functions.input(
         self.style.WARNING("Save to dictionary (yes)?"))[0]
     if action not in ("yes", "YES", "y", "Y"):
         return
     word = functions.save(result)
     if word:
         print(self.style.SUCCESS("Save to dictionary success."))
         self.operate_review(word)
     else:
         print(self.style.ERROR("Save to dictionary failure."))
         functions.getch()
Ejemplo n.º 5
0
    def handle(self, *args, **options):
        edited = {}

        queryset = models.Paraphrase.objects.extra(
            where=['content REGEXP %s and content REGEXP %s '],
            params=[r'^[\S]*$', r'.*][^ ].*'],
        ).filter(
            word__review__isnull=False,
        ).distinct().order_by("-word__review__review_time")
        count = queryset.count()
        print("Count %s" % count)
        while True:
            count -= 1
            if count < 0:
                break
            para = queryset[count]
            word = para.word

            if word.title in edited:
                continue
            edited[word.title] = True
            url = "http://steven-arch.local/zh-hans/edit/{}/".format(para.word.id)
            review = para.word.review.first()
            if review:
                review_time = timezone.localtime(review.review_time)
            else:
                review_time = timezone.now()

            print(self.style.SUCCESS("{} {} {}".format(review_time.strftime("%Y-%m-%d %H"), para.word.title, url)))
            try:
                key = ord(functions.getch())
                if key == 101:
                    return
                webbrowser.open_new_tab(url)
            except Exception:
                print(Exception)
Ejemplo n.º 6
0
 def right(self, word):
     key = functions.getch()
     if key == "r":
         models.Review.objects.get_or_create(word=word)
         print(styles.SUCCESS("Save to review success!!!"))