# wordlink
![wordlink logo](/logo.png)
A Word Link Generator that searches for a given term in multiple text files within a specified directory and generates links to the matched occurrences. It provides two output options: an HTML file with clickable links or a console display using a formatted table.
The `__main__.py` file is located in the `/wordlink/` directory.
## Prerequisites
- Python 3.x
- `argparse` library
- `fuzzysearch` library
- `prettytable` library
## Installation
1. Clone the repository or download the script file.
2. Install the required libraries by running the following command:
```bash
pip install wordlink
```
See [INSTALL](INSTALL) for instructions to clone from GitHub.
## Usage
Run the script using the following command:
```bash
python3 wordlink <search_term> <search_directory> [-o OUTPUT_FILE]
```
- `<search_term>`: The term to search for within the text files.
- `<search_directory>`: The directory to search for text files.
- `-o OUTPUT_FILE` or `--output_file OUTPUT_FILE`: (Optional) Specify the output file name to save the results as an HTML file. If not provided, the results will be displayed in the console using a formatted table.
**Examples:**
Search for the term "example" in the current directory and display the results in the console:
```bash
python3 wordlink example .
```
Search for the term "example" in the directory "documents" and save the results as an HTML file named "output.html":
```bash
python3 wordlink example documents -o output.html
```
See the `/examples/readme.md` for instructions on running a demo of the wordlink module.
## Output
The tool generates two types of output depending on the presence of the output file option:
1. **HTML Output File:** If an output file is specified using the `-o` or `--output_file` option, the tool generates an HTML file with clickable links. Each link represents a matched occurrence in a specific file and line. The output file contains a table with columns for the file name, line number, and corresponding text.
2. **Console Display:** If no output file is provided, the tool displays the results in the console using a formatted table. The console output includes columns for the file name, line number, and corresponding text.
## Tests
The tool includes a test suite to ensure its functionality. The `main_test.py` file contains the unit tests. Here's a description of what each test case in `main_test.py` is testing:
- `test_find_word_locations`: This test verifies that the `find_word_locations` method correctly identifies the locations of the given search term within a test file.
- `test_generate_links_output_file`: This test checks if the `generate_links` method generates the expected output file in HTML format when an output file name is provided.
- `test_generate_links_console`: This test validates that the `generate_links` method produces the expected console output when no output file name is provided.
To run the tests, navigate to the `/tests/` directory and execute the following command:
```bash
python3 main_test.py
```
## Limitations
- The tool searches for the specified term within all text files (`.txt`) in the given directory and its subdirectories. It does not support searching within other file formats.
- The maximum Levenshtein distance for finding near matches is set to 1. This can be adjusted by modifying the `max_l_dist` parameter in the `find_near_matches` function call within the `find_word_locations` method.
## License
This code is provided under the [MIT License](LICENSE). Feel free to modify and use it according to your needs.
Raw data
{
"_id": null,
"home_page": "https://github.com/psibir/wordlink",
"name": "wordlink",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "word,link,html,console",
"author": "Trevor Bloomfield",
"author_email": "bloomfieldtm@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e5/d9/5f5e77062eb3b12d44383c20d2c365bc73470b82a62ad34a948b99d78aae/wordlink-1.0.7.tar.gz",
"platform": null,
"description": "# wordlink\n\n![wordlink logo](/logo.png)\n\nA Word Link Generator that searches for a given term in multiple text files within a specified directory and generates links to the matched occurrences. It provides two output options: an HTML file with clickable links or a console display using a formatted table.\nThe `__main__.py` file is located in the `/wordlink/` directory.\n\n## Prerequisites\n\n- Python 3.x\n- `argparse` library\n- `fuzzysearch` library\n- `prettytable` library\n\n## Installation\n\n1. Clone the repository or download the script file.\n2. Install the required libraries by running the following command:\n\n ```bash\n pip install wordlink\n ```\n\nSee [INSTALL](INSTALL) for instructions to clone from GitHub.\n\n## Usage\n\nRun the script using the following command:\n\n```bash\npython3 wordlink <search_term> <search_directory> [-o OUTPUT_FILE]\n```\n\n- `<search_term>`: The term to search for within the text files.\n- `<search_directory>`: The directory to search for text files.\n- `-o OUTPUT_FILE` or `--output_file OUTPUT_FILE`: (Optional) Specify the output file name to save the results as an HTML file. If not provided, the results will be displayed in the console using a formatted table.\n\n**Examples:**\n\nSearch for the term \"example\" in the current directory and display the results in the console:\n\n ```bash\n python3 wordlink example .\n ```\n\nSearch for the term \"example\" in the directory \"documents\" and save the results as an HTML file named \"output.html\":\n\n ```bash\n python3 wordlink example documents -o output.html\n ```\n\nSee the `/examples/readme.md` for instructions on running a demo of the wordlink module.\n\n## Output\n\nThe tool generates two types of output depending on the presence of the output file option:\n\n1. **HTML Output File:** If an output file is specified using the `-o` or `--output_file` option, the tool generates an HTML file with clickable links. Each link represents a matched occurrence in a specific file and line. The output file contains a table with columns for the file name, line number, and corresponding text.\n\n2. **Console Display:** If no output file is provided, the tool displays the results in the console using a formatted table. The console output includes columns for the file name, line number, and corresponding text.\n\n## Tests\n\nThe tool includes a test suite to ensure its functionality. The `main_test.py` file contains the unit tests. Here's a description of what each test case in `main_test.py` is testing:\n\n- `test_find_word_locations`: This test verifies that the `find_word_locations` method correctly identifies the locations of the given search term within a test file.\n- `test_generate_links_output_file`: This test checks if the `generate_links` method generates the expected output file in HTML format when an output file name is provided.\n- `test_generate_links_console`: This test validates that the `generate_links` method produces the expected console output when no output file name is provided.\n\nTo run the tests, navigate to the `/tests/` directory and execute the following command:\n\n```bash\npython3 main_test.py\n```\n\n## Limitations\n\n- The tool searches for the specified term within all text files (`.txt`) in the given directory and its subdirectories. It does not support searching within other file formats.\n- The maximum Levenshtein distance for finding near matches is set to 1. This can be adjusted by modifying the `max_l_dist` parameter in the `find_near_matches` function call within the `find_word_locations` method.\n\n## License\n\nThis code is provided under the [MIT License](LICENSE). Feel free to modify and use it according to your needs.\n",
"bugtrack_url": null,
"license": "",
"summary": "Word Link Generator",
"version": "1.0.7",
"project_urls": {
"Download": "https://github.com/psibir/wordlink/archive/v_01.tar.gz",
"Homepage": "https://github.com/psibir/wordlink"
},
"split_keywords": [
"word",
"link",
"html",
"console"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "80a223d81ce4833ac1c6795fa81e7fc4606d4a843e7780aa77ebfe9c2fa95a2b",
"md5": "23652e39d185c21ff65fdecd32575240",
"sha256": "7fcc0d39c3e0604b3edce5a70c236d01d83a396a296c6c235baf439bd45e5f71"
},
"downloads": -1,
"filename": "wordlink-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "23652e39d185c21ff65fdecd32575240",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 6366,
"upload_time": "2023-05-24T21:50:45",
"upload_time_iso_8601": "2023-05-24T21:50:45.352289Z",
"url": "https://files.pythonhosted.org/packages/80/a2/23d81ce4833ac1c6795fa81e7fc4606d4a843e7780aa77ebfe9c2fa95a2b/wordlink-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e5d95f5e77062eb3b12d44383c20d2c365bc73470b82a62ad34a948b99d78aae",
"md5": "f29b618b7bac02c824df3f6f159ab91e",
"sha256": "520dc613e86895ca135c2a9a8037e856ad40218c4fade5d6d6669a8127edf439"
},
"downloads": -1,
"filename": "wordlink-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "f29b618b7bac02c824df3f6f159ab91e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5893,
"upload_time": "2023-05-24T21:50:47",
"upload_time_iso_8601": "2023-05-24T21:50:47.109105Z",
"url": "https://files.pythonhosted.org/packages/e5/d9/5f5e77062eb3b12d44383c20d2c365bc73470b82a62ad34a948b99d78aae/wordlink-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-24 21:50:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "psibir",
"github_project": "wordlink",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "attrs",
"specs": [
[
"==",
"23.1.0"
]
]
},
{
"name": "fuzzysearch",
"specs": [
[
"==",
"0.7.3"
]
]
},
{
"name": "prettytable",
"specs": [
[
"==",
"3.7.0"
]
]
},
{
"name": "wcwidth",
"specs": [
[
"==",
"0.2.6"
]
]
},
{
"name": "wheel",
"specs": [
[
"==",
"0.37.0"
]
]
}
],
"lcname": "wordlink"
}