From 1a3fc86ffc743d0560fac3eb08381c94e7abab3f Mon Sep 17 00:00:00 2001 From: justuser Date: Thu, 14 Nov 2024 21:51:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=D0=B0?= =?UTF-8?q?/=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20=D0=B8=D0=B7=20ou?= =?UTF-8?q?t.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- txt_convert.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 txt_convert.py diff --git a/txt_convert.py b/txt_convert.py new file mode 100644 index 0000000..420d1e4 --- /dev/null +++ b/txt_convert.py @@ -0,0 +1,43 @@ +from db import * + +op = input('op [exp/imp]: ') +mode = input('mode [0/1]: ') + +if mode != '0' and mode != '1': + print('Wrong mode, exit...') + exit() + +db = read() +if op == 'exp': + out_text = '' + for i in db[mode]: + out_text += i + '\n' + with open('out.txt', 'w') as f: + f.write(out_text) + f.close() + print('Exported!') +elif op == 'imp': + print('Select mode: append/replace') + op_mode = input('app/rep (app): ') + + with open('out.txt', 'r') as f: + lines = f.read().split('\n') + f.close() + words = [] + for i in lines: + words.append(i) + words.remove('') + + if op_mode == 'app' or op_mode == '': + # Add existing words + words += db[mode] + print('Appending...') + elif op_mode == 'rep': + print('Replacing...') + + # Remove duplicates + words = list(set(words)) + + db[mode] = words + write(db) +