Example#
In this page, we demonstrate using some components
import todobricks
For this toy example, we’ll write the todo file out from there first and then read it back in.
toy_list = ['x post example +todobricks @code due:2022-08-18',
'x document bricks +todobricks @code due:2022-08-17',
'write sample function doc strings @prismia +todobricks',
'write up answers to questions +tdadmin @prismia']
Then we can write it out
todobricks.write_file(toy_list,'todo.txt')
and we can read it in
todobricks.read_txt_file('todo.txt')
'x post example +todobricks @code due:2022-08-18\nx document bricks +todobricks @code due:2022-08-17\nwrite sample function doc strings @prismia +todobricks\nwrite up answers to questions +tdadmin @prismia\n'
To save it to a variable to use it, we use assignment
todo_list_read = todobricks.read_txt_file('todo.txt')
This still looks like before
todo_list_read
'x post example +todobricks @code due:2022-08-18\nx document bricks +todobricks @code due:2022-08-17\nwrite sample function doc strings @prismia +todobricks\nwrite up answers to questions +tdadmin @prismia\n'
Then we can split it to be able to work with it
todo_list = todobricks.split_txt_file(todo_list_read)
And now we can look at it again:
todo_list
['x post example +todobricks @code due:2022-08-18',
'x document bricks +todobricks @code due:2022-08-17',
'write sample function doc strings @prismia +todobricks',
'write up answers to questions +tdadmin @prismia']
This we can check the type
type(todo_list)
list
We can count the tasks
todobricks.count_tasks(todo_list)
4
We can also group items by context
todobricks.group_tasks(todo_list,by="context")
{'prismia': ['write sample function doc strings @prismia +todobricks',
'write up answers to questions +tdadmin @prismia'],
'code': ['x post example +todobricks @code due:2022-08-18',
'x document bricks +todobricks @code due:2022-08-17'],
'none': []}
This returns a dictionary
todo_by_context = todobricks.group_tasks(todo_list,by="context")
type(todo_by_context)
dict