def execute(self): part = NoteModel(name=self.model_name, id=self.model_id, css=self.css, fields=self.fields, templates=self.templates, required_fields_per_template=[]) PartHolder.override_or_create(self.part_id, self.save_to_file, part)
def execute(self): self.verify_contents() csv_data_by_guid: Dict[str, dict] = {} for csv_map in self.file_mappings: csv_map.compile_data() csv_data_by_guid = {**csv_data_by_guid, **csv_map.compiled_data} csv_map.write_file_on_close() csv_rows: List[dict] = list(csv_data_by_guid.values()) notes_part: List[Note] = [self.csv_row_to_note(row, self.note_model_mappings) for row in csv_rows] notes = Notes.from_list_of_notes(notes_part) PartHolder.override_or_create(self.part_id, self.save_to_file, notes)
def from_repr(cls, data: Union[Representation, dict]): rep: cls.Representation = data if isinstance( data, cls.Representation) else cls.Representation.from_dict(data) return cls(rep=rep, part=PartHolder.override_or_create( part_id=rep.part_id, save_to_file=None, part=NoteModel.from_yaml_file(rep.file)))
def execute(self): ca_wrapper: CrowdAnkiJsonWrapper = self.ca_export.json_data note_models_dict = {model.get('name'): model for model in ca_wrapper.note_models} if self.model_name not in note_models_dict: raise ReferenceError(f"Missing Note Model '{self.model_name}' in CrowdAnki file") part = NoteModel.from_crowdanki(note_models_dict[self.model_name]) return PartHolder.override_or_create(self.part_id, self.save_to_file, part)
def from_repr(cls, data: Union[Representation, dict]): rep: cls.Representation = data if isinstance( data, cls.Representation) else cls.Representation.from_dict(data) return cls(rep=rep, notes=PartHolder.from_file_manager(rep.notes), file_mappings=rep.get_file_mappings(), note_model_mappings={ k: v for nm in rep.note_model_mappings for k, v in cls.map_nmm(nm).items() })
def from_repr(cls, data: Union[Representation, dict]): rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data) return cls( rep=rep, notes=PartHolder.from_file_manager(rep.part_id).part, sort_order=SharedBaseNotes._get_sort_order(rep.sort_order), reverse_sort=SharedBaseNotes._get_reverse_sort(rep.reverse_sort), additional_items_to_add=rep.additional_items_to_add or {}, override=NotesOverride.from_repr(rep.override) if rep.override else None, case_insensitive_sort=rep.case_insensitive_sort or True )
def from_repr(cls, data: Union[Representation, dict]): rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data) return cls( rep=rep, headers=PartHolder.override_or_create( part_id=rep.part_id, save_to_file=None, part=Headers.from_yaml_file(rep.file) ).part, override=HeadersOverride.from_repr(rep.override) if rep.override else None )
def from_repr(cls, data: Union[Representation, dict, str]): rep: cls.Representation if isinstance(data, cls.Representation): rep = data elif isinstance(data, dict): rep = cls.Representation.from_dict(data) else: rep = cls.Representation(part_id=data) # Support single string being passed in return cls( rep=rep, headers=PartHolder.from_file_manager(rep.part_id).part )
def execute(self) -> PartHolder[Notes]: ca_wrapper: CrowdAnkiJsonWrapper = self.ca_export.json_data if ca_wrapper.children: logging.warning("Child Decks / Sub-decks are not currently supported.") ca_models = self.ca_export.note_models ca_notes = ca_wrapper.notes nm_id_to_name: dict = {model.id: model.name for model in ca_models} note_list = [self.ca_note_to_note(note, nm_id_to_name) for note in ca_notes] notes = Notes.from_list_of_notes(note_list) # TODO: pass in sort method return PartHolder.override_or_create(self.part_id, self.save_to_file, notes)
def from_repr(cls, data: Union[Representation, dict]): rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data) note_models = [PartHolder.from_file_manager(model) for model in single_item_to_list(rep.note_models)] return cls( columns_manually_mapped=[FieldMapping( field_type=FieldMapping.FieldMappingType.COLUMN, field_name=f, value=key) for key, f in rep.columns_to_fields.items()] if rep.columns_to_fields else [], personal_fields=[FieldMapping( field_type=FieldMapping.FieldMappingType.PERSONAL_FIELD, field_name=f, value="") for f in rep.personal_fields], note_models=dict(map(lambda nm: (nm.part_id, nm), note_models)) )
def execute(self) -> List[PartHolder[NoteModel]]: ca_wrapper: CrowdAnkiJsonWrapper = self.ca_export.json_data note_models_dict = { model.get('name'): model for model in ca_wrapper.note_models } parts = [] for name, model in note_models_dict.items(): parts.append( PartHolder.override_or_create(name, None, NoteModel.from_crowdanki(model))) logging.info( f"Found {len(parts)} note model{'s' if len(parts) > 1 else ''} in CrowdAnki Export: '" + "', '".join(note_models_dict.keys()) + "'") return parts
def create_media_group_from_location( part_id: str, save_to_file: str, media_group: MediaGroup, groups_to_blacklist: List[MediaContainer], groups_to_whitelist: List[MediaContainer]) -> MediaGroup: if groups_to_whitelist: white = list( set.union(*[ container.get_all_media_references() for container in groups_to_whitelist ])) media_group.filter_by_filenames(white, should_match=True) if groups_to_blacklist: black = list( set.union(*[ container.get_all_media_references() for container in groups_to_blacklist ])) media_group.filter_by_filenames(black, should_match=False) holder = PartHolder.override_or_create(part_id, save_to_file, media_group) return holder.part
def debug_write_part_to_file(part, filepath: str): dp = PartHolder("Blah", filepath, part) dp.save_to_file = filepath dp.write_to_file()
def get_note_model(self) -> PartHolder[NoteModel]: self.part = PartHolder.from_file_manager(self.part_to_read) return self.part # Todo: add filters in here
def execute(self): ca_wrapper: CrowdAnkiJsonWrapper = self.ca_export.json_data headers = Headers(self.crowd_anki_to_headers(ca_wrapper.data)) return PartHolder.override_or_create(self.part_id, self.save_to_file, headers)