Skip to content

Replaces text based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys)

License

Notifications You must be signed in to change notification settings

cainky/ReplaceText

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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):

    curl -sSL https://install.python-poetry.org | python3 -
  2. Clone the repository and navigate to the project directory:

    git clone https://github.com/cainky/ReplaceText.git
    cd ReplaceText
  3. Install dependencies:

    poetry install

Configuration

  1. Rename the example configuration file:

    mv example_config.json config.json
  2. Edit config.json to define your dictionaries. Here is an example

    {
      "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:

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-keys

Folder 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, allowing for free software distribution and modification while ensuring that all copies and modified versions remain free.

About

Replaces text based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages