Exemple #1
0
    def find_cards(
        self,
        query: str,
        order: Union[bool, str, BuiltinSort.Kind.V] = False,
        reverse: bool = False,
    ) -> Sequence[int]:
        """Return card ids matching the provided search.

        To programmatically construct a search string, see .build_search_string().

        If order=True, use the sort order stored in the collection config
        If order=False, do no ordering

        If order is a string, that text is added after 'order by' in the sql statement.
        You must add ' asc' or ' desc' to the order, as Anki will replace asc with
        desc and vice versa when reverse is set in the collection config, eg
        order="c.ivl asc, c.due desc".

        If order is a BuiltinSort.Kind value, sort using that builtin sort, eg
        col.find_cards("", order=BuiltinSort.Kind.CARD_DUE)

        The reverse argument only applies when a BuiltinSort.Kind is provided;
        otherwise the collection config defines whether reverse is set or not.
        """
        if isinstance(order, str):
            mode = _pb.SortOrder(custom=order)
        elif isinstance(order, bool):
            if order is True:
                mode = _pb.SortOrder(from_config=_pb.Empty())
            else:
                mode = _pb.SortOrder(none=_pb.Empty())
        else:
            mode = _pb.SortOrder(
                builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
        return self._backend.search_cards(search=query, order=mode)
Exemple #2
0
 def drag_drop_decks(self, *, source_deck_ids: Sequence[int],
                     target_deck_id: int) -> pb.Empty:
     input = pb.DragDropDecksIn(source_deck_ids=source_deck_ids,
                                target_deck_id=target_deck_id)
     output = pb.Empty()
     output.ParseFromString(self._run_command(57, input))
     return output
Exemple #3
0
 def drag_drop_tags(self, *, source_tags: Sequence[str],
                    target_tag: str) -> pb.Empty:
     input = pb.DragDropTagsIn(source_tags=source_tags,
                               target_tag=target_tag)
     output = pb.Empty()
     output.ParseFromString(self._run_command(109, input))
     return output
Exemple #4
0
 def bury_or_suspend_cards(
         self, *, card_ids: Sequence[int],
         mode: pb.BuryOrSuspendCardsIn.Mode.V) -> pb.Empty:
     input = pb.BuryOrSuspendCardsIn(card_ids=card_ids, mode=mode)
     output = pb.Empty()
     output.ParseFromString(self._run_command(24, input))
     return output
Exemple #5
0
 def find_cards(
     self,
     query: str,
     order: Union[bool, str, BuiltinSort.Kind.V] = False,
     reverse: bool = False,
 ) -> Sequence[int]:
     if isinstance(order, str):
         mode = _pb.SortOrder(custom=order)
     elif isinstance(order, bool):
         if order is True:
             mode = _pb.SortOrder(from_config=_pb.Empty())
         else:
             mode = _pb.SortOrder(none=_pb.Empty())
     else:
         mode = _pb.SortOrder(
             builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
     return self._backend.search_cards(search=query, order=mode)
Exemple #6
0
 def extend_limits(self, *, deck_id: int, new_delta: int,
                   review_delta: int) -> pb.Empty:
     input = pb.ExtendLimitsIn(deck_id=deck_id,
                               new_delta=new_delta,
                               review_delta=review_delta)
     output = pb.Empty()
     output.ParseFromString(self._run_command(19, input))
     return output
Exemple #7
0
 def open_collection(self, *, collection_path: str, media_folder_path: str,
                     media_db_path: str, log_path: str) -> pb.Empty:
     input = pb.OpenCollectionIn(collection_path=collection_path,
                                 media_folder_path=media_folder_path,
                                 media_db_path=media_db_path,
                                 log_path=log_path)
     output = pb.Empty()
     output.ParseFromString(self._run_command(87, input))
     return output
Exemple #8
0
 def after_note_updates(self, *, nids: Sequence[int],
                        mark_notes_modified: bool,
                        generate_cards: bool) -> pb.Empty:
     input = pb.AfterNoteUpdatesIn(nids=nids,
                                   mark_notes_modified=mark_notes_modified,
                                   generate_cards=generate_cards)
     output = pb.Empty()
     output.ParseFromString(self._run_command(76, input))
     return output
Exemple #9
0
 def update_stats(self, *, deck_id: int, new_delta: int, review_delta: int,
                  millisecond_delta: int) -> pb.Empty:
     input = pb.UpdateStatsIn(deck_id=deck_id,
                              new_delta=new_delta,
                              review_delta=review_delta,
                              millisecond_delta=millisecond_delta)
     output = pb.Empty()
     output.ParseFromString(self._run_command(18, input))
     return output
Exemple #10
0
 def sort_cards(self, *, card_ids: Sequence[int], starting_from: int,
                step_size: int, randomize: bool,
                shift_existing: bool) -> pb.Empty:
     input = pb.SortCardsIn(card_ids=card_ids,
                            starting_from=starting_from,
                            step_size=step_size,
                            randomize=randomize,
                            shift_existing=shift_existing)
     output = pb.Empty()
     output.ParseFromString(self._run_command(29, input))
     return output
Exemple #11
0
 def answer_card(self, *, card_id: int, current_state: pb.SchedulingState,
                 new_state: pb.SchedulingState,
                 rating: pb.AnswerCardIn.Rating.V, answered_at_millis: int,
                 milliseconds_taken: int) -> pb.Empty:
     input = pb.AnswerCardIn(card_id=card_id,
                             current_state=current_state,
                             new_state=new_state,
                             rating=rating,
                             answered_at_millis=answered_at_millis,
                             milliseconds_taken=milliseconds_taken)
     output = pb.Empty()
     output.ParseFromString(self._run_command(34, input))
     return output
Exemple #12
0
 def get_all_config(self) -> bytes:
     input = pb.Empty()
     output = pb.Json()
     output.ParseFromString(self._run_command(113, input))
     return output.json
Exemple #13
0
 def remove_config(self, val: str) -> pb.Empty:
     input = pb.String(val=val)
     output = pb.Empty()
     output.ParseFromString(self._run_command(112, input))
     return output
Exemple #14
0
 def set_config_json(self, *, key: str, value_json: bytes) -> pb.Empty:
     input = pb.SetConfigJsonIn(key=key, value_json=value_json)
     output = pb.Empty()
     output.ParseFromString(self._run_command(111, input))
     return output
Exemple #15
0
 def sync_media(self, input: pb.SyncAuth) -> pb.Empty:
     output = pb.Empty()
     output.ParseFromString(self._run_command(90, input))
     return output
Exemple #16
0
 def all_tags(self) -> Sequence[str]:
     input = pb.Empty()
     output = pb.StringList()
     output.ParseFromString(self._run_command(105, input))
     return output.vals
Exemple #17
0
 def get_preferences(self) -> pb.Preferences:
     input = pb.Empty()
     output = pb.Preferences()
     output.ParseFromString(self._run_command(118, input))
     return output
Exemple #18
0
 def i18n_resources(self) -> bytes:
     input = pb.Empty()
     output = pb.Json()
     output.ParseFromString(self._run_command(102, input))
     return output.json
Exemple #19
0
 def close_collection(self, downgrade_to_schema11: bool) -> pb.Empty:
     input = pb.CloseCollectionIn(
         downgrade_to_schema11=downgrade_to_schema11)
     output = pb.Empty()
     output.ParseFromString(self._run_command(88, input))
     return output
Exemple #20
0
 def full_download(self, input: pb.SyncAuth) -> pb.Empty:
     output = pb.Empty()
     output.ParseFromString(self._run_command(98, input))
     return output
Exemple #21
0
 def before_upload(self) -> pb.Empty:
     input = pb.Empty()
     output = pb.Empty()
     output.ParseFromString(self._run_command(93, input))
     return output
Exemple #22
0
 def abort_media_sync(self) -> pb.Empty:
     input = pb.Empty()
     output = pb.Empty()
     output.ParseFromString(self._run_command(92, input))
     return output
Exemple #23
0
 def set_config_bool(self, *, key: pb.Config.Bool.Key.V,
                     value: bool) -> pb.Empty:
     input = pb.SetConfigBoolIn(key=key, value=value)
     output = pb.Empty()
     output.ParseFromString(self._run_command(115, input))
     return output
Exemple #24
0
 def set_tag_expanded(self, *, name: str, expanded: bool) -> pb.Empty:
     input = pb.SetTagExpandedIn(name=name, expanded=expanded)
     output = pb.Empty()
     output.ParseFromString(self._run_command(106, input))
     return output
Exemple #25
0
 def set_config_string(self, *, key: pb.Config.String.Key.V,
                       value: str) -> pb.Empty:
     input = pb.SetConfigStringIn(key=key, value=value)
     output = pb.Empty()
     output.ParseFromString(self._run_command(117, input))
     return output
Exemple #26
0
 def clear_tag(self, val: str) -> pb.Empty:
     input = pb.String(val=val)
     output = pb.Empty()
     output.ParseFromString(self._run_command(107, input))
     return output
Exemple #27
0
 def set_preferences(self, input: pb.Preferences) -> pb.Empty:
     output = pb.Empty()
     output.ParseFromString(self._run_command(119, input))
     return output
Exemple #28
0
 def tag_tree(self) -> pb.TagTreeNode:
     input = pb.Empty()
     output = pb.TagTreeNode()
     output.ParseFromString(self._run_command(108, input))
     return output
Exemple #29
0
 def clear_unused_tags(self) -> pb.Empty:
     input = pb.Empty()
     output = pb.Empty()
     output.ParseFromString(self._run_command(104, input))
     return output
Exemple #30
0
 def check_database(self) -> Sequence[str]:
     input = pb.Empty()
     output = pb.CheckDatabaseOut()
     output.ParseFromString(self._run_command(89, input))
     return output.problems