tools4zettelkasten package¶
Submodules¶
tools4zettelkasten.analyse module¶
- class tools4zettelkasten.analyse.Analysis(list_of_filenames: list, list_of_explicit_links: list, list_of_structure_links: list, list_of_links: list, tree: list)¶
Bases:
object- list_of_explicit_links: list[tools4zettelkasten.reorganize.Link]¶
- list_of_filenames: list[str]¶
- list_of_links: list[tools4zettelkasten.reorganize.Link]¶
- list_of_structure_links: list[tools4zettelkasten.reorganize.Link]¶
- tree: list¶
- tools4zettelkasten.analyse.create_graph_analysis(persistencyManager: tools4zettelkasten.persistency.PersistencyManager) tools4zettelkasten.analyse.Analysis¶
- tools4zettelkasten.analyse.create_graph_of_zettelkasten(list_of_filenames: list[str], list_of_links: list[tools4zettelkasten.reorganize.Link], url_in_nodes: bool) graphviz.graphs.Digraph¶
- tools4zettelkasten.analyse.show_graph_of_zettelkasten(dot: graphviz.graphs.Digraph)¶
- tools4zettelkasten.analyse.show_tree_as_list(tree)¶
tools4zettelkasten.app module¶
tools4zettelkasten.cli module¶
The command line interface.
Click is used as backbone for the cli. An excellent tutorial is found at “https://zetcode.com/python/click”.
- class tools4zettelkasten.cli.Command¶
Bases:
object
- class tools4zettelkasten.cli.Replace_command(filename: str, to_be_replaced: str, replace_with: str)¶
Bases:
tools4zettelkasten.cli.Command- filename: str¶
- replace_with: str¶
- to_be_replaced: str¶
- tools4zettelkasten.cli.batch_rename(command_list, persistencyManager: tools4zettelkasten.persistency.PersistencyManager)¶
rename a bunch of file
prompt user to verify that rename should be done
- Parameters
command_list (list) – A list of rename commands. Each command is a list with three entries. name of command, must be rename. oldfilename original name of file. newfilename name of file after rename operation.
persistencyManager (PersistencyManager) – handler for manipulation of the file system
- tools4zettelkasten.cli.batch_replace(command_list: list[tools4zettelkasten.cli.Replace_command], persistencyManager: tools4zettelkasten.persistency.PersistencyManager)¶
- tools4zettelkasten.cli.check_directories()¶
- tools4zettelkasten.cli.overwrite_setting(environment_variable: str)¶
- tools4zettelkasten.cli.overwrite_settings()¶
- tools4zettelkasten.cli.show_banner()¶
tools4zettelkasten.flask_views module¶
- class tools4zettelkasten.flask_views.PageDownForm(*args, **kwargs)¶
Bases:
flask_wtf.form.FlaskForm- pagedown = <UnboundField(PageDownField, ('Enter your markdown',), {})>¶
- submit = <UnboundField(SubmitField, ('Submit',), {})>¶
- tools4zettelkasten.flask_views.edit(filename)¶
- tools4zettelkasten.flask_views.index()¶
- tools4zettelkasten.flask_views.run_flask_server()¶
Run the flask server
- tools4zettelkasten.flask_views.send_image(filename)¶
- tools4zettelkasten.flask_views.show_md_file(file)¶
- tools4zettelkasten.flask_views.svggraph()¶
- tools4zettelkasten.flask_views.url_for_file(filename) ast.Str¶
tools4zettelkasten.handle_filenames module¶
- tools4zettelkasten.handle_filenames.create_Note(filename) tools4zettelkasten.note.Note¶
create a Note object from a filename
- Parameters
filename (str) – The filename of a note
- Returns
Note object
- Return type
- tools4zettelkasten.handle_filenames.create_base_filename_from_title(title)¶
Create a standard base filename
Suppose you have a title like 5 Dinge für mein Thema. This will give Dinge_fuer_mein_Thema This string is suited as a standard base filename for the Zettelkasten.
- Parameters
title (str) – The title of the note
- Returns
base_filename
- Return type
str
- tools4zettelkasten.handle_filenames.create_filename(ordering, base_filename, id) str¶
Creates a standard filename
- Parameters
ordering (str) – The ordering of the note
base_filename (str) – The base of the filename
id (str) – The id of the note
- Returns
filename
- Return type
str
- tools4zettelkasten.handle_filenames.currentTimestamp()¶
- tools4zettelkasten.handle_filenames.evaluate_sha_256(input)¶
- tools4zettelkasten.handle_filenames.generate_id(filename)¶
generates an unique Id for a file
IDs have the form of 8 hex digits. Like fb134b00b. As collisions are unlikely but not impossible the seed is peppered with a timestamp.
- Parameters
filename (string) – The filename of a note
- Returns
id in form of 8 hex digits
- Return type
str
- tools4zettelkasten.handle_filenames.get_filename_components(filename)¶
Decomposes a standard note filename
A standard filename has the form of 2_03_04a_5_Some_Topic_fb134b00b Where 2_03_04a_5 define the order within the hierachy of notes (in this case 4 levels), Some_Topic is the base of the filename and fb134b00b is a unique identifier. The return value is [‘2_03_04a_5’,’Some_Topic’,’fb134b00b’]
- Parameters
filename (str) – The filename of a note
- Returns
List of strings with the components of the filename
- Return type
list
- tools4zettelkasten.handle_filenames.is_valid_basefilename(base_filename)¶
checks if a base filename is valid
- Parameters
base_filename (str) – The base of the filename
- Returns
True if the base filename is valid
- Return type
bool
- tools4zettelkasten.handle_filenames.is_valid_filename(filename) bool¶
checks if a filename is valid
- Parameters
filename (str) – The filename of a note
- Returns
True if the filename is valid
- Return type
bool
- tools4zettelkasten.handle_filenames.is_valid_id(id)¶
checks if an id is valid
- Parameters
id (str) – The id of a note
- Returns
True if the id is valid
- Return type
bool
- tools4zettelkasten.handle_filenames.is_valid_ordering(ordering)¶
checks if an ordering is valid
- Parameters
ordering (str) – The ordering of a note
- Returns
True if the ordering is valid
- Return type
bool
tools4zettelkasten.note module¶
- class tools4zettelkasten.note.Note(ordering: str, base_filename: str, id: str)¶
Bases:
objectA note standard filenames have the form of 2_03_04a_5_Some_Topic_fb134b00b
The correct form of the filenames is important for listing, reorganizing the Zettelkasten etc.
- base_filename: str¶
“The base of the filename
- id: str¶
The id of the note
- ordering: str¶
The ordering of the note
tools4zettelkasten.persistency module¶
- class tools4zettelkasten.persistency.PersistencyManager(directory)¶
Bases:
objectInterface class for all the persistency functionality
Later we can add the same functionality on different persistency mechanisms (like local folder, dropbox, AWS-S3 etc.)
- get_file_content(filename)¶
- get_list_of_filenames()¶
- get_string_from_file_content(filename)¶
- is_file_existing(filename)¶
- is_markdown_file(filename)¶
- is_text_file(filename)¶
- overwrite_file_content(filename, new_content)¶
- rename_file(oldfilename, newfilename)¶
- tools4zettelkasten.persistency.file_content(directory, filename)¶
- tools4zettelkasten.persistency.get_string_from_file_content(directory, filename)¶
- tools4zettelkasten.persistency.is_file_existing(directory, filename) bool¶
- tools4zettelkasten.persistency.is_markdown_file(filename)¶
- tools4zettelkasten.persistency.is_text_file(filename)¶
- tools4zettelkasten.persistency.list_of_filenames_from_directory(directory)¶
returns a list of all files in a directory
Hidden files are excluded from the list
- Parameters
directory (path) – name of the directory
- Returns
list of the names of the files in the directory
- Return type
list
- tools4zettelkasten.persistency.overwrite_file_content(directory, filename, new_content)¶
- tools4zettelkasten.persistency.rename_file(directory, oldfilename, newfilename)¶
renames a file in a directory
- Parameters
directory (path) – the name of the directory containing the file to be renamed
oldfilename (string) – original name of the file
newfilename (string) – new name of the file
tools4zettelkasten.reorganize module¶
- class tools4zettelkasten.reorganize.Link(source: str, description: str, target: str)¶
Bases:
objectObject for representing a link between notes
- description: str¶
- source: str¶
- target: str¶
- tools4zettelkasten.reorganize.attach_missing_ids(file_name_list)¶
Generates a list of commands to attach missing ids by renaming files
Suppose we have the following list as input:
[‘5_10_Senescent_cells_9e051e2c4.md’, ‘1_2_reframe_your_goal_as_a_learning_goal.md’, ‘2_1a_render_md_files_with_python_and_flask_41e5a496c.md’, ‘2_5_homebrew.md’]
Then the following command_list will be retrurned:
[[‘rename’, ‘1_2_reframe_your_goal_as_a_learning_goal.md’, ‘1_2_reframe_your_goal_as_a_learning_goal_7ae870951.md’], [‘rename’, ‘2_5_homebrew.md’, ‘2_5_homebrew_fe38ebbaa.md’]]
Remark: The Ids are seeded with the timestamp. So the Ids will change with every new run of the program or test.
- Parameters
file_name_list (list of strings) – List of files in a given directory which might contain filenames with missing ids.
- Returns
list of commands. Each command is a list with three components. the command (i.e. rename), the old filename and the new filename.
- Return type
list of list of strings
ToDo: * Implement mechanism to resolve hash collisions
- tools4zettelkasten.reorganize.attach_missing_orderings(file_name_list)¶
attaches the missing orderings to the files in the file_name_list
- tools4zettelkasten.reorganize.corrections_elements(list_of_keys)¶
corrects numberings to canonical form
Suppose you have named your files in one level and one subtree like as follows.
[‘1’, ‘2’, ‘4’, ‘5’, ‘5a’, ‘6’, ‘7’, ‘8’, ‘8a’, ‘8b’, ‘9’]
Then you get a dictionary which you can use to bring the numbers to a canonical form:
{‘1’: ‘01’, ‘2’: ‘02’, ‘4’: ‘03’, ‘5’: ‘04’, ‘5a’: ‘05’, ‘6’: ‘06’, ‘7’: ‘07’, ‘8’: ‘08’, ‘8a’: ‘09’, ‘8b’: ‘10’, ‘9’: ‘11’}
- Parameters
list_of_keys (list) – numbering keys of one subtree and one level
- Returns
what key to set for which original key to get a canonical numbering
- Return type
dictionary
- tools4zettelkasten.reorganize.create_rename_commands(potential_changes_of_filenames)¶
- tools4zettelkasten.reorganize.generate_dictionary(zettelkasten_list: list[str]) dict[str, str]¶
generates a list from a list of Zettelkasten filenames
- Parameters
zettelkasten_list (list[str]) – List of filenames in the Zettelkasten
- Returns
dictionary with the id as keys and the filename as values
- Return type
dictionary
- tools4zettelkasten.reorganize.generate_list_of_link_correction_commands(persistencyManager: tools4zettelkasten.persistency.PersistencyManager)¶
- tools4zettelkasten.reorganize.generate_tokenized_list(zettelkasten_list)¶
generates a list of tokens from a file list
Suppose the list of filenames for input is:
[‘5_10_Senescent_cells_9e051e2c4.md’, ‘1_2_reframe_your_goal_as_a_learning_goal_ab9df245b.md’, ‘2_1a_render_md_files_with_python_and_flask.md_41e5a496c’, ‘2_5_homebrew.md_282f521b1’]
Then the function will return:
[[[‘5’, ‘10’], ‘5_10_Senescent_cells_9e051e2c4.md’], [[‘1’, ‘2’], ‘1_2_reframe_your_goal_as_a_learning_goal_ab9df245b.md’], [[‘2’, ‘1a’], ‘2_1a_render_md_files_with_python_and_flask.md_41e5a496c’], [[‘2’, ‘5’], ‘2_5_homebrew.md_282f521b1’]]
- Parameters
zettelkasten_list (list) – the list of filennames
- Returns
a list of list of ordering items and filenames
- Return type
list
- tools4zettelkasten.reorganize.generate_tree(tokenized_list)¶
generates a tree from a tokenized list
Suppose we have the following files:
[‘1_first_topic_41b4e4f8f.md’, ‘1_1_a_Thought_on_first_topic_2c3c34ff5.md’, ‘1_2_another_Thought_on_first_topic_2af216153.md’, ‘2_Second_Topic_cc6290ab7.md’, ‘2_1_a_Thought_on_Second_Topic_176fb43ae.md’]
After tokenizing (which is done elsewhere) we get
[[[‘1’], ‘1_first_topic_41b4e4f8f.md’], [[‘1’, ‘1’], ‘1_1_a_Thought_on_first_topic_2c3c34ff5.md’], [[‘1’, ‘2’], ‘1_2_another_Thought_on_first_topic_2af216153.md’], [[‘2’], ‘2_Second_Topic_cc6290ab7.md’], [[‘2’, ‘1’], ‘2_1_a_Thought_on_Second_Topic_176fb43ae.md’]]
This is our input. generate_tree will do a recursion to form a tree like:
- [[‘1’, ‘1_first_topic_41b4e4f8f.md’,
[[‘1’, ‘1_1_a_Thought_on_first_topic_2c3c34ff5.md’], [‘2’, ‘1_2_another_Thought_on_first_topic_2af216153.md’]]],
- [‘2’, ‘2_Second_Topic_cc6290ab7.md’,
[[‘1’, ‘2_1_a_Thought_on_Second_Topic_176fb43ae.md’]]]]
- Parameters
tokenized_list (list) – the tokenized list of hierchical files
- Returns
structured tree
- Return type
list
- tools4zettelkasten.reorganize.getChildNodesThatAreLeafs(node)¶
- tools4zettelkasten.reorganize.get_hierarchy_links(tree, hierarchy_links=None)¶
- tools4zettelkasten.reorganize.get_list_of_invalid_links(persistency_manager: tools4zettelkasten.persistency.PersistencyManager)¶
- tools4zettelkasten.reorganize.get_list_of_links(persistency_manager: tools4zettelkasten.persistency.PersistencyManager)¶
- tools4zettelkasten.reorganize.get_list_of_links_from_file(filename, lines_of_filecontent)¶
find all links in a file
Only links to other files are returned. Links for images are ignored.
- Parameters
lines_of_filecontent (list of strings) – the content of the file as list of strings
- Returns
list of Link dataclass objects
- Return type
list of Link objects
- tools4zettelkasten.reorganize.isLeaf(node)¶
- tools4zettelkasten.reorganize.isLeafWithSubtree(node)¶
- tools4zettelkasten.reorganize.isStructureNode(node)¶
- tools4zettelkasten.reorganize.reorganize_filenames(tree, path=None, final=None)¶
tools4zettelkasten.settings module¶
tools4zettelkasten.stage module¶
- tools4zettelkasten.stage.process_files_from_input(persistencyManager: tools4zettelkasten.persistency.PersistencyManager)¶
- tools4zettelkasten.stage.process_txt_file(persistencyManager: tools4zettelkasten.persistency.PersistencyManager, filename)¶