Keyword finder
SearchResult
dataclass
Class to hold the results of a file search. file_path: The path to the file that was searched. word_count: A dictionary containing the number of times each keyword was found in the file.
Source code in quinn/keyword_finder.py
57 58 59 60 61 62 63 64 65 |
|
keyword_format(input, keywords=default_keywords)
Formats the input string to highlight the keywords.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
str
|
The string to format. |
required |
keywords |
list[str]
|
The list of keywords to highlight. |
default_keywords
|
Source code in quinn/keyword_finder.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
search_file(path, keywords=default_keywords)
Searches a file for keywords and prints the line number and line containing the keyword.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the file to search. |
required |
keywords |
list[str]
|
The list of keywords to search for. |
default_keywords
|
Returns:
Type | Description |
---|---|
SearchResult
|
A dictionary containing a file path and the number of lines containing a keyword in |
Source code in quinn/keyword_finder.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
search_files(path, keywords=default_keywords)
Searches all files in a directory for keywords.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the directory to search. |
required |
keywords |
list[str]
|
The list of keywords to search for. |
default_keywords
|
Returns:
Type | Description |
---|---|
list[SearchResult]
|
A list of dictionaries containing file paths and the number of lines containing a keyword in |
Source code in quinn/keyword_finder.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
surround_substring(input, substring, surround_start, surround_end)
Surrounds a substring with the given start and end strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
str
|
The string to search. |
required |
substring |
str
|
The substring to surround. |
required |
surround_start |
str
|
The string to start the surrounding with. |
required |
surround_end |
str
|
The string to end the surrounding with. |
required |
Returns:
Type | Description |
---|---|
str
|
The input string with the substring surrounded. |
Source code in quinn/keyword_finder.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|