Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cainky/replacetext
Replaces text based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys)
https://github.com/cainky/replacetext
batch-processing python text-processing text-replacement utility
Last synced: about 1 month ago
JSON representation
Replaces text based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys)
- Host: GitHub
- URL: https://github.com/cainky/replacetext
- Owner: cainky
- License: gpl-3.0
- Created: 2024-08-06T16:43:09.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-06T19:14:36.000Z (5 months ago)
- Last Synced: 2024-08-06T22:18:55.174Z (5 months ago)
- Topics: batch-processing, python, text-processing, text-replacement, utility
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ReplaceText
This project replaces text in files based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys).
## Features
- Replace text in files based on dictionaries defined in a configuration file.
- Allows user to specify the direction of replacement (keys-to-values or values-to-keys).
- Allows user to specify which file extensions, file prefixes, or directories to ignore.
- Automatically uses the only dictionary if only one is defined in the configuration file.## Requirements
- Python 3.8 or higher
- Poetry package manager## Installation
1. **Install Poetry** (if not already installed):
```sh
curl -sSL https://install.python-poetry.org | python3 -
```2. **Clone the repository and navigate to the project directory**:
```sh
git clone https://github.com/cainky/ReplaceText.git
cd ReplaceText
```3. **Install dependencies**:
```sh
poetry install
```## Configuration
1. **Rename the example configuration file**:
```sh
mv example_config.json config.json
```2. **Edit `config.json` to define your dictionaries**. Here is an example
```json
{
"dictionaries": {
"example1": {
"key1": "value1",
"key2": "value2",
"key3": "value3"
},
"example2": {
"hello": "world",
"foo": "bar",
"python": "rocks"
}
},
"ignore_extensions": [".exe", ".dll", ".bin"],
"ignore_directories": ["node_modules", "venv", ".git"],
"ignore_file_prefixes": [".", "_"]
}
```## Usage
Run the script using Poetry:
```sh
poetry run python replace_text/replace_text.py
```The script will prompt you for the following inputs:
Direction of replacement:
- Enter '1' for keys-to-values
- Enter '2' for values-to-keysFolder path:
- Enter the path to the folder containing the files to be processed.
Dictionary name:
- Enter the name of the dictionary to use from config.json.
The script will process all files in the specified folder, replacing text based on the selected dictionary and direction.## License
ReplaceText is distributed under the [GNU General Public License, Version 3](./LICENSE), allowing for free software distribution and modification while ensuring that all copies and modified versions remain free.