Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Release version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Aug 15, 2023
1 parent 7ce8b21 commit f4e2bfa
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 92 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
test.py
/old code
**/__pycache__
userOptions.py
userOptions.py

# others
**/*temp*
**/*test*
13 changes: 7 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@
### 🐣 CƠ BẢN

1. Cài đặt [Python](https://www.python.org/downloads/)
2. [Tải repo](https://github.com/KevinNitroG/Dict-Tool/archive/refs/heads/main.zip), giải nén
3. Chuẩn bị dictionary:
2. [Tải repo](https://github.com/KevinNitroG/Dict-Tool/archive/refs/heads/main.zip), giải nén, vào folder repo
3. Mở terminal chạy `pip install -r requirements.txt`
4. Chuẩn bị dictionary:
- **Cách 1:** Paste file dictionary vào folder [Dictionary In](../Dictionary%20In/)
- **Cách 2:** Copy paste nội dung vào biến `your_dictionary` file [userConstant.py](../userConstants.py)
> Script sẽ ưu tiên trong file [userConstant.py](../userConstants.py)
4. Chạy file [DictTool.py](../DictTool.py)
5. Dictionary sẽ được tạo ra ở folder [Dictionary Out](../Dictionary%20Out/)
5. Chạy file [main.py](../main.py)
6. Dictionary sẽ được tạo ra ở folder [Dictionary Out](../Dictionary%20Out/)

> **Note**
>
Expand All @@ -65,12 +66,12 @@

## 🥰 MORE...

- Bạn có thể yêu cầu thêm bộ gõ tại [Issues](https://github.com/KevinNitroG/Dict-Tool/issues)
- thể yêu cầu thêm bộ gõ tại [Issues](https://github.com/KevinNitroG/Dict-Tool/issues)
- Có thể tạo **Pull Request** thêm về bộ gõ, format nằm trong file [dictionaryList.py](../dictionaryList.py)

---

## 🧓 VERSION HISTORY:
## 🧓 VERSION HISTORY

Go to here 👉: [version_history.md](version_history.md)

Expand Down
6 changes: 6 additions & 0 deletions docs/version_history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 🧓 VERSION HISTORY

# 1.2

- Bruh rename [DictTools.py](../DictTool.py) to [main.py](../main.py)
- Add decorate function
- Add `requests` module to handle network status with LaTeX function, also add skip LaTeX if no LaTeX dict is found

# 1.1

- **Code changes:**
Expand Down
17 changes: 4 additions & 13 deletions DictTool.py → main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ def main():
prTitle("PREPARE")
print(prLightPurple("Reading your dictionary...\n"))
switch_pwd(input_dict_folder)
all_dict_zip_file = [dict['dictionary_zip_file'] for dict in dictionary_list if dict['dictionary_zip_file'] is not None]
all_dict_zip_file = [dict['dictionary_zip_file'] for dict in dictionary_list if dict['dictionary_zip_file']]
# read your dict file
working_dict = read_current_dict(your_dictionary, all_dict_zip_file)
# detect your dict file
current_dict = detect_current_dict_type(working_dict, dictionary_list)
# create re_compile_pattern for current dict
current_dict['re_compile_pattern'] = create_re_compile_pattern(current_dict['format'])
# Specify the format type of current dict
current_dict['format_type'] = specify_format_type(current_dict['format'])
# split each line into parts using re.match
working_dict = split_dict(working_dict, current_dict["re_compile_pattern"], current_dict['format_type'])
working_dict = split_dict(working_dict, current_dict["re_compile_pattern"])
switch_pwd('../')
print()
print(prGreen("Done reading!"))
Expand All @@ -57,12 +55,6 @@ def main():

# EXECUTE OPTIONAL FUNCTIONS
prTitle("EXECUTE FUNCTIONS")
print(prLightPurple("WORKING..."))
print()

# # Remove LaTeX old
# if ask_remove_latex == 'Y' or ask_remove_latex == '':
# working_dict = remove_latex(working_dict)

# LaTeX function - compare user input inside function
working_dict = latex_function(working_dict, ask_latex_function)
Expand All @@ -76,14 +68,12 @@ def main():

# Convert dict
if ask_convert_dict == 'Y':
print(prLightPurple("Chọn loại dictionary convert sang:"))
print(prBlue("Chọn loại dictionary convert sang:"))
print()
# select your dict to convert
selected_dict = select_dict_type(dictionary_list)
# create re_compile_pattern for selected dict
selected_dict['re_compile_pattern'] = create_re_compile_pattern(selected_dict['format'])
# Specify the format type of selected dict
selected_dict['format_type'] = specify_format_type(selected_dict['format'])
else:
selected_dict = current_dict

Expand Down Expand Up @@ -112,6 +102,7 @@ def main():
prTitle("TẠO FILE MACRO")
switch_pwd(output_dict_folder)
create_converted_dictionary_as_file(working_dict, selected_dict)
print()
wait_for_pressed_key()

exit_program("Kết thúc chương trình ^^")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
66 changes: 34 additions & 32 deletions src/compulsoryFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,39 @@
from .pr import *


# SHORT VARS EXPLANATION

# yd = your_dict
# adzf = all_dict_zip_files
# lold = list_of_line_dict
# cf = current_format
# wd = working_dict
# rc_p = current_dict['re_compile_pattern']
# dl = dict_list


def read_current_dict(yd, adzf):
# yd = your_dict
# adzf = all_dict_zip_files
# lold = list_of_line_dict
'''Đọc dictionary'''
yd = yd.strip().strip("\n")
list_dir = []
if yd != '':
lold = yd.splitlines()
else:
delete_dir('./Extracted Folder')
delete_dir('./Extracted Dict')
list_dir = [f for f in os.listdir() if (f.endswith('.txt') or True for zip_file_name in adzf if fnmatch.fnmatch(f, zip_file_name))]
if list_dir == []:
exit_program("Không tìm thấy bất kì file macro có sẵn trong thư mục hiện tại", 1)
# List out the list of file with number
print(prLightPurple("Chọn file macro:\n"))
for i, file in enumerate(list_dir, start=1):
print(f"{str(i).rjust(5)}. {file}")
print("{}. {}".format(str(i).rjust(5), file))
_ = int(input("\nNhập số thứ tự file bạn muốn chọn: "))
print()
selected_file_name = list_dir[_-1]
# If selection is a dictionary zip file
if selected_file_name.endswith('.zip'):
with zipfile.ZipFile(selected_file_name, 'r') as zip_ref:
switch_pwd('./Extracted Folder')
switch_pwd('./Extracted Dict')
zip_ref.extractall("./")
os.rename(zip_ref.namelist()[0], 'extracted_dictionary.txt')
with open('extracted_dictionary.txt', 'r', encoding='utf-8') as file:
Expand All @@ -42,51 +52,43 @@ def read_current_dict(yd, adzf):


def create_re_compile_pattern(cf):
# cf = current_format
cf = re.escape(cf).replace('\\{sort\\}', '{sort}').replace('\\{long\\}', '{long}')
cf = cf.replace('{sort}', '(.*)').replace('{long}', '(.*)')
'''Tạo re.compile pattern'''
cf = re.escape(cf).replace('\\{sort\\}', '(?P<sort>.*)').replace('\\{long\\}', '(?P<long>.*)')
return cf


def specify_format_type(cf):
# cf = current_format
if cf.index('{sort}') < cf.index('{long}'):
return 1
return 2
# Detech which type is the dict, {sort} before {long} or vice versa
# def specify_format_type(cf):
# # cf = current_format
# if cf.index('{sort}') < cf.index('{long}'):
# return 1
# return 2


def split_dict(wd, rc_p, ft):
# wd = working_dict
# rc_p = current_dict['re_compile_pattern']
# ft = current_dict['format_type']
def split_dict(wd, rc_p):
'''Tách dictionary thành list'''
pattern = re.compile(rc_p)
if ft == 1:
for i in range(1, len(wd)):
match = re.search(pattern, wd[i])
wd[i] = [match.group(1), match.group(2)]
else:
for i in range(1, len(wd)):
match = re.search(pattern, wd[i])
wd[i] = [match.group(2), match.group(1)]
for i in range(1, len(wd)):
match = re.search(pattern, wd[i])
wd[i] = [match.group('sort'), match.group('long')]
return wd


def select_dict_type(dl):
# dl = dict_list
'''Chọn loại dictionary'''
for i, dict_type in enumerate(dl, start=1):
print("{}. {}".format(str(i).rjust(5), dict_type["name"]))
print()
_ = input(prYellow("Chọn thứ tự: "))
_ = input("Chọn thứ tự: ")
return dl[int(_)-1]


def detect_current_dict_type(wd, dl):
# wd = working_dict
# dl = dict_list
'''Tự động nhận diện loại dictionary'''
first_line = wd[0][:-1]
for dict_type in dl:
if first_line in dict_type["first_line"]:
_ = input("\nPhát hiện dictionary hiện tại là {}? [Y/n]: ".format(dict_type["name"])).upper()
_ = input("Dictionary hiện tại là {}? [Y/n]: ".format(dict_type["name"])).upper()
if _ == 'Y' or _ == '':
return dict_type
else:
Expand All @@ -102,5 +104,5 @@ def detect_current_dict_type(wd, dl):


def join_working_dict(wd):
# wd = working_dict
'''Gộp list dictionary hoàn chỉnh'''
return '\n'.join(wd)
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
"""
maintainer = "KevinNitro"
version = '1.0'
version = '1.2'

# # ANSI ESCAPE SEQUENCES
# BLACK = "\033[0;30m"
Expand Down
24 changes: 12 additions & 12 deletions src/optional_functions/confirmCharacter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from ..utils import prYellow, prGreen
from ..utils import prYellow, prGreen, decorator


# SHORT VARS EXPLAINATION

# wd = working_dict
# cc = confirm_character
# a_ccf = ask_confirm_character_function


def remove_confirm_character(wd, cc):
# wd = list of dictionary
# cc = confirm_character
'''Xoá confirm character'''
for i in range(1, len(wd)):
if wd[i][0].endswith(cc):
wd[i][0] = wd[i][0][:-len(cc)]
Expand All @@ -12,23 +18,17 @@ def remove_confirm_character(wd, cc):


def add_confirm_character(wd, cc):
# wd = list of dictionary
# cc = confirm_character
'''Thêm confirm character'''
for i in range(1, len(wd)):
wd[i] = [wd[i][0] + cc, wd[i][1]]
return wd


@decorator
def confirm_character_function(wd, a_ccf, cc):
# wd = working_dict
# a_ccf = ask_confirm_character_function
# cc = confirm_character
'''Confirm character'''
if a_ccf == 'R' or a_ccf == 'U':
print(prYellow("Đang xoá Confirm Character trong Dictionary hiện tại..."))
wd = remove_confirm_character(wd, cc)
print(prGreen("Done"))
if a_ccf == 'A' or a_ccf == 'U':
print(prYellow("Đang thêm Confirm Character vào Dictionary hiện tại..."))
wd = add_confirm_character(wd, cc)
print(prGreen("Done"))
return wd
18 changes: 12 additions & 6 deletions src/optional_functions/createDictFile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import os

from ..pr import *
from ..utils import decorator


# SHORT VARS EXPLANATIONS

# fd = final_dictionary
# sd = selected_dict


def dictionary_compress(sd):
Expand All @@ -22,9 +29,9 @@ def evkey_special_create_file(content, evkey_macro):
print(prGreen("File macro đã được tạo ^^. Tên file: ") + prPurple(evkey_macro))


@decorator
def create_converted_dictionary_as_file(fd, sd):
# fd = final_dictionary
# sd = selected_dict
'''Tạo file dictionary'''
_ = 'Y'
if os.path.exists(sd['macro']):
_ = input("File macro đã hiện có tại đường dẫn hiện tại, có muốn ghi đè [Y/n]: ").upper()
Expand All @@ -35,10 +42,9 @@ def create_converted_dictionary_as_file(fd, sd):
with open(sd['macro'], 'w', encoding="utf-8") as file:
file.write(fd)
print(prGreen("File macro đã được tạo ^^. Tên file: ") + prPurple(sd['macro']))
print()
if sd['dictionary_zip_file'] is not None:
_ = input(prYellow("Tạo file zip dictionary [Y/n]: "))
if sd['dictionary_zip_file']:
_ = input("Tạo file zip dictionary [Y/n]: ")
if _ == 'Y' or _ == '':
dictionary_compress(sd)
else:
print(prCyan("\nĐã huỷ tạo file macro"))
print(prCyan("Đã huỷ tạo file macro"))
Loading

0 comments on commit f4e2bfa

Please sign in to comment.