Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
feat(config): config folder on home .config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Jul 12, 2021
1 parent ace7704 commit 4aa7eb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,3 @@ pip-selfcheck.json


# End of https://www.gitignore.io/api/python

stats.json
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ For the UI is required PyQt5.

Doesn't create conflicts with [Espanso](https://espanso.org/).

## How to use with Target Language(s)
### Settings and assets files (dictionaries)

Automatically will create a folder inside '~/.config/SyntaxAutoFix` that will include the stats.json files.
Also will look for the dictionaries and settings also on this folder so this let you customize it without define commandline parameters.

## Usage

### How to use with Target Language(s)

- For English only
```
syntaxautofix -words ./words/en.json
Expand All @@ -30,7 +38,7 @@ syntaxautofix -words ./words/en.json -words2 ./words/it.json
syntaxautofix -configini /path/config.ini
```

## Adding New Terms
### Adding New Terms

This require the git repo or the right path to the pip package folder.

Expand All @@ -40,7 +48,7 @@ manageterms.py -wrong="wdiget" -right="widget" -lang=en

You can use also an ui for that: `manageterms-gui.py`

## Adding New Terms using CSV File
### Adding New Terms using a CSV File

This require the git repo or the right path to the pip package folder.

Expand Down
27 changes: 20 additions & 7 deletions SyntaxAutoFix/syntaxautofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@
import json

script_path = os.path.dirname(os.path.realpath(__file__))
config_parser = ConfigParser()
def getHomePath():
user = os.getenv("SUDO_USER") or os.getenv("USER")
home = os.path.join(os.path.expanduser('~' + user), '.config/SyntaxAutoFix')
if not os.path.exists(home):
os.mkdir(home)
return home

def getAssetPath(path):
home = getHomePath()
complete_path = os.path.join(home, path)
if not os.path.exists(complete_path):
complete_path = os.path.join(script_path, path)
return complete_path

config_parser = ConfigParser()

# Load words
def loadWord(filename):
Expand All @@ -23,14 +36,14 @@ def loadWord(filename):

# Parse argument
parser = argparse.ArgumentParser(description='Scan your digited letter for wrong words and alert you!')
parser.add_argument('-config', dest='configini', nargs='?', default=os.path.join(script_path, 'config.ini'), type=str)
parser.add_argument('-words', dest='words_file', nargs='?', default=os.path.join(script_path, 'words/en.json'), type=str)
parser.add_argument('-words2', dest='words_file2', nargs='?', default=os.path.join(script_path, 'words/it.json'), type=str)
parser.add_argument('-config', dest='configini', nargs='?', default=getAssetPath('config.ini'), type=str)
parser.add_argument('-words', dest='words_file', nargs='?', default=getAssetPath('words/en.json'), type=str)
parser.add_argument('-words2', dest='words_file2', nargs='?', default=getAssetPath('words/it.json'), type=str)
args = parser.parse_args()

config_parser.read(args.configini)
LIST_OF_FILES = json.loads(config_parser.get('DEFAULT', 'words_file'))
WORDS_FILE_DEFAULT_LOCATION = [os.path.join(script_path, file_path) for file_path in LIST_OF_FILES]
WORDS_FILE_DEFAULT_LOCATION = [getAssetPath(file_path) for file_path in LIST_OF_FILES]

# it holds the files name passed and the stat os file
files = {}
Expand All @@ -43,7 +56,8 @@ def mispell_callback():
list_splitted = recorded_words_list[0].split()
if len(list_splitted) > 0:
wrong_word = list_splitted[-1]
save_stats_file(os.path.join(script_path, "stats.json"), wrong_word, 1)
print("Word '" + wrong_word + "' detected and tracked")
save_stats_file(os.path.join(getHomePath(), "stats.json"), wrong_word, 1)
keyboard.start_recording()


Expand All @@ -70,7 +84,6 @@ def loadJSON():
for (correct, wrongs) in words.items():
for wrong in wrongs:
if wrong != '':
print('Loaded ' + wrong + ' with as: ' + correct)
keyboard.add_abbreviation(wrong, ' ' + correct + ' ')
keyboard.add_word_listener(wrong, mispell_callback)

Expand Down

0 comments on commit 4aa7eb8

Please sign in to comment.