py2ls 0.1.4.7__py3-none-any.whl → 0.1.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py2ls/.git/COMMIT_EDITMSG +1 -1
- py2ls/.git/FETCH_HEAD +1 -1
- py2ls/.git/config +1 -0
- py2ls/.git/index +0 -0
- py2ls/.git/logs/HEAD +3 -0
- py2ls/.git/logs/refs/heads/main +3 -0
- py2ls/.git/logs/refs/remotes/origin/HEAD +5 -0
- py2ls/.git/logs/refs/remotes/origin/main +3 -0
- py2ls/.git/objects/01/d5bd8065e6860c0bd23ff9fa57161806a099e1 +0 -0
- py2ls/.git/objects/09/08da26de58c114225ad81f484b80bf5d351b34 +0 -0
- py2ls/.git/objects/1c/3f92adda34344bcbbbf9d409c79855ae2aaea8 +2 -0
- py2ls/.git/objects/32/fd627b62fad7cf3b2f9e34ab9777126a0987ad +0 -0
- py2ls/.git/objects/39/7ead045fbbcfb17c62019eb18fe21ed05dbee5 +0 -0
- py2ls/.git/objects/4f/7afb40dff2153d857fc85748c2eecb85125042 +0 -0
- py2ls/.git/objects/62/4488173ed2c8936fa5cea3cf5dd3f26a30b86e +0 -0
- py2ls/.git/objects/6d/ee29dbdcc84edeeacede105110446f3ccac963 +0 -0
- py2ls/.git/objects/b7/2c9e75ab7d0afe594664650aa8f6c772f5ac64 +0 -0
- py2ls/.git/objects/bb/81ccc0513f18fc160b54a82861e9a80d23f4f6 +0 -0
- py2ls/.git/objects/cd/822b3574a88ebdd1ed82fd6983f37e626d52b4 +0 -0
- py2ls/.git/objects/d8/4688b54c0040a30976b3a6540bc47adf7ce680 +0 -0
- py2ls/.git/objects/f1/e50757fddc28b445545dc7e2759b54cdd0f42e +0 -0
- py2ls/.git/refs/heads/main +1 -1
- py2ls/.git/refs/remotes/origin/main +1 -1
- py2ls/__init__.py +1 -1
- py2ls/data/.DS_Store +0 -0
- py2ls/data/db2ls_sql_chtsht.json +39 -0
- py2ls/data/lang_code_iso639.json +97 -0
- py2ls/db2ls.py +356 -0
- py2ls/ips.py +542 -226
- py2ls/netfinder.py +452 -128
- py2ls/translator.py +80 -122
- {py2ls-0.1.4.7.dist-info → py2ls-0.1.4.9.dist-info}/METADATA +1 -1
- {py2ls-0.1.4.7.dist-info → py2ls-0.1.4.9.dist-info}/RECORD +34 -18
- {py2ls-0.1.4.7.dist-info → py2ls-0.1.4.9.dist-info}/WHEEL +1 -1
- py2ls/dbhandler.py +0 -97
py2ls/translator.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import re
|
2
|
+
import json
|
2
3
|
import docx # pip install python-docx
|
3
4
|
from PyPDF2 import PdfReader
|
4
5
|
from langdetect import detect
|
@@ -13,6 +14,7 @@ import numpy as np
|
|
13
14
|
from nltk.tokenize import sent_tokenize
|
14
15
|
from itertools import pairwise
|
15
16
|
from tqdm import tqdm
|
17
|
+
from fuzzywuzzy import fuzz,process
|
16
18
|
|
17
19
|
|
18
20
|
def split_by_sent_n(text,n=10):
|
@@ -57,107 +59,80 @@ def get_lang_code_iso639():
|
|
57
59
|
lang_code_iso639=dict([*zip(fullname,shortcut)])
|
58
60
|
return lang_code_iso639
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
'
|
77
|
-
|
78
|
-
'
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
'
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
'
|
110
|
-
|
111
|
-
'
|
112
|
-
|
113
|
-
'
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
'
|
122
|
-
|
123
|
-
'
|
124
|
-
|
125
|
-
'
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
'Swahili': 'sw',
|
135
|
-
'Swati': 'ss',
|
136
|
-
'Tajik': 'tg',
|
137
|
-
'Tamil': 'ta',
|
138
|
-
'Telugu': 'te',
|
139
|
-
'Thai': 'th',
|
140
|
-
'Tibetan': 'bo',
|
141
|
-
'Tigrinya': 'ti',
|
142
|
-
'Tonga (Tonga Islands)': 'to',
|
143
|
-
'Tsonga': 'ts',
|
144
|
-
'Twi': 'tw',
|
145
|
-
'Ukrainian': 'uk',
|
146
|
-
'Urdu': 'ur',
|
147
|
-
'Uzbek': 'uz',
|
148
|
-
'Venda': 've',
|
149
|
-
'Vietnamese': 'vi',
|
150
|
-
'Volapük': 'vo',
|
151
|
-
'Welsh': 'cy',
|
152
|
-
'Wolof': 'wo',
|
153
|
-
'Xhosa': 'xh',
|
154
|
-
'Yiddish': 'yi',
|
155
|
-
'Yoruba': 'yo',
|
156
|
-
'Zulu': 'zu'}
|
157
|
-
def search_iso639_fullname(val):
|
158
|
-
for k,v in lang_code_iso639.items():
|
159
|
-
if 'de' in v:
|
160
|
-
return k
|
62
|
+
def detect_lang(text, output='lang',verbose=True):
|
63
|
+
dir_curr_script=os.path.dirname(os.path.abspath(__file__))
|
64
|
+
dir_lang_code=dir_curr_script+"/data/lang_code_iso639.json"
|
65
|
+
with open(dir_lang_code, "r") as file:
|
66
|
+
lang_code_iso639 = json.load(file)
|
67
|
+
l_lang,l_code = [],[]
|
68
|
+
[[l_lang.append(v),l_code.append(k)] for v,k in lang_code_iso639.items()]
|
69
|
+
try:
|
70
|
+
if is_text(text):
|
71
|
+
code_detect=detect(text)
|
72
|
+
if 'c' in output.lower(): # return code
|
73
|
+
return l_code[strcmp(code_detect,l_code, verbose=verbose)[1]]
|
74
|
+
else:
|
75
|
+
return l_lang[strcmp(code_detect,l_code, verbose=verbose)[1]]
|
76
|
+
else:
|
77
|
+
print(f"{text} is not supported")
|
78
|
+
return 'no'
|
79
|
+
except:
|
80
|
+
return 'no'
|
81
|
+
|
82
|
+
def is_text(s):
|
83
|
+
has_alpha = any(char.isalpha() for char in s)
|
84
|
+
has_non_alpha = any(not char.isalpha() for char in s)
|
85
|
+
# no_special = not re.search(r'[^A-Za-z0-9\s]', s)
|
86
|
+
return has_alpha and has_non_alpha
|
87
|
+
|
88
|
+
def strcmp(search_term, candidates, ignore_case=True, verbose=True, scorer='WR'):
|
89
|
+
"""
|
90
|
+
Compares a search term with a list of candidate strings and finds the best match based on similarity score.
|
91
|
+
|
92
|
+
Parameters:
|
93
|
+
search_term (str): The term to be searched for.
|
94
|
+
candidates (list of str): A list of candidate strings to compare against the search term.
|
95
|
+
ignore_case (bool): If True, the comparison ignores case differences.
|
96
|
+
verbose (bool): If True, prints the similarity score and the best match.
|
97
|
+
|
98
|
+
Returns:
|
99
|
+
tuple: A tuple containing the best match and its index in the candidates list.
|
100
|
+
"""
|
101
|
+
def to_lower(s, ignore_case=True):
|
102
|
+
#Converts a string or list of strings to lowercase if ignore_case is True.
|
103
|
+
if ignore_case:
|
104
|
+
if isinstance(s, str):
|
105
|
+
return s.lower()
|
106
|
+
elif isinstance(s, list):
|
107
|
+
return [elem.lower() for elem in s]
|
108
|
+
return s
|
109
|
+
str1_,str2_ = to_lower(search_term, ignore_case),to_lower(candidates, ignore_case)
|
110
|
+
if isinstance(str2_, list):
|
111
|
+
if 'part' in scorer.lower():
|
112
|
+
similarity_scores = [fuzz.partial_ratio(str1_, word) for word in str2_]
|
113
|
+
elif 'W' in scorer.lower():
|
114
|
+
similarity_scores = [fuzz.WRatio(str1_, word) for word in str2_]
|
115
|
+
elif 'Ratio' in scorer.lower():
|
116
|
+
similarity_scores = [fuzz.Ratio(str1_, word) for word in str2_]
|
117
|
+
else:
|
118
|
+
similarity_scores = [fuzz.WRatio(str1_, word) for word in str2_]
|
119
|
+
best_match_index = similarity_scores.index(max(similarity_scores))
|
120
|
+
best_match_score = similarity_scores[best_match_index]
|
121
|
+
else:
|
122
|
+
best_match_index = 0
|
123
|
+
if 'part' in scorer.lower():
|
124
|
+
best_match_score = fuzz.partial_ratio(str1_, str2_)
|
125
|
+
elif 'W' in scorer.lower():
|
126
|
+
best_match_score = fuzz.WRatio(str1_, str2_)
|
127
|
+
elif 'Ratio' in scorer.lower():
|
128
|
+
best_match_score = fuzz.Ratio(str1_, str2_)
|
129
|
+
else:
|
130
|
+
best_match_score = fuzz.WRatio(str1_, str2_)
|
131
|
+
if verbose:
|
132
|
+
print(f"\nbest_match is: {candidates[best_match_index],best_match_score}")
|
133
|
+
best_match = process.extract(search_term, candidates)
|
134
|
+
print(f"建议: {best_match}")
|
135
|
+
return candidates[best_match_index], best_match_index
|
161
136
|
|
162
137
|
|
163
138
|
def methods(idx=0):
|
@@ -231,23 +206,6 @@ def get_language_code(language, translator="google"):
|
|
231
206
|
# print(f"Google Translate Language Code for '{language}': {google_lang_code}")
|
232
207
|
# print(f"DeepL Translator Language Code for '{language}': {deepl_lang_code}")
|
233
208
|
|
234
|
-
def detect_language(text):
|
235
|
-
"""
|
236
|
-
Detect the language of the given text.
|
237
|
-
"""
|
238
|
-
if len(text.strip()) < 3:
|
239
|
-
print("Error: Input text is too short for language detection.")
|
240
|
-
return "english"
|
241
|
-
else:
|
242
|
-
lang_code = detect(text)
|
243
|
-
detected_language=search_iso639_fullname(lang_code)
|
244
|
-
print(detected_language)
|
245
|
-
return detected_language
|
246
|
-
|
247
|
-
|
248
|
-
# text_to_detect = "Bonjour, comment ça va?"
|
249
|
-
# detected_language = detect_language(text_to_detect)
|
250
|
-
# print("Detected language:", detected_language)
|
251
209
|
|
252
210
|
def load_docx(filename):
|
253
211
|
"""
|
@@ -438,13 +396,13 @@ def translate(
|
|
438
396
|
text=merge_text(text)
|
439
397
|
text = replace_text(text)
|
440
398
|
if lang_src is None:
|
441
|
-
lang_src =
|
399
|
+
lang_src = detect_lang(text)
|
442
400
|
try:
|
443
401
|
if len(text) > limit:
|
444
402
|
n=auto_chunk_size(text)
|
445
403
|
text_segments = split_by_sent_n(text,n)
|
446
404
|
translations = ""
|
447
|
-
for segment in tqdm(text_segments,desc='is translating'):
|
405
|
+
for segment in tqdm(text_segments,desc='is translating', colour="green"):
|
448
406
|
segment = replace_text(merge_text(segment))
|
449
407
|
translated_segment = translate_segment(text=segment, lang=lang, lang_src=lang_src, method=method, user_agent=user_agent,service_urls=service_urls, verbose=verbose,error_verbose=error_verbose
|
450
408
|
)
|
@@ -479,7 +437,7 @@ def translate_segment(
|
|
479
437
|
text_clean = filter_errors(text)
|
480
438
|
text_clean = replace_text(text_clean)
|
481
439
|
if lang_src is None:
|
482
|
-
lang_src =
|
440
|
+
lang_src = detect_lang(text_clean)
|
483
441
|
try:
|
484
442
|
lang_src = get_language_code(lang_src, 'google')
|
485
443
|
lang_tgt = get_language_code(lang, 'google')
|
@@ -547,7 +505,7 @@ def translate_with_retry(
|
|
547
505
|
raise RuntimeError(f"Error using {service_url}: {e}")
|
548
506
|
|
549
507
|
if lang_src is None:
|
550
|
-
lang_src =
|
508
|
+
lang_src = detect_lang(text)
|
551
509
|
lang_src = get_language_code(language=lang_src)
|
552
510
|
lang = get_language_code(language=lang)
|
553
511
|
print(f"lang:{lang},lang_src:{lang_src}")
|
@@ -1,8 +1,8 @@
|
|
1
1
|
py2ls/.DS_Store,sha256=1lFlJ5EFymdzGAUAaI30vcaaLHt3F1LwpG7xILf9jsM,6148
|
2
|
-
py2ls/.git/COMMIT_EDITMSG,sha256=
|
3
|
-
py2ls/.git/FETCH_HEAD,sha256
|
2
|
+
py2ls/.git/COMMIT_EDITMSG,sha256=D-zrSGq7SOvKoes1LN7CjdO3CKzT1iov7qtEa1SfeKs,20
|
3
|
+
py2ls/.git/FETCH_HEAD,sha256=-VcbSEQggMjAywR171vGJ3V6maA_20WhC6AjtyZQOWg,100
|
4
4
|
py2ls/.git/HEAD,sha256=KNJb-Cr0wOK3L1CVmyvrhZ4-YLljCl6MYD2tTdsrboA,21
|
5
|
-
py2ls/.git/config,sha256=
|
5
|
+
py2ls/.git/config,sha256=CL7WR7jU8VRchJwRooCBkXUMvuRoPdf3FWIBAOlap1c,378
|
6
6
|
py2ls/.git/description,sha256=ZzMxc0Ca26m45Twn1DDnOHqin5VHEZ9uOTBrScIXSjE,16
|
7
7
|
py2ls/.git/hooks/applypatch-msg.sample,sha256=AiNJeguLAzqlijpSG4YphpOGz3qw4vEBlj0yiqYhk_c,478
|
8
8
|
py2ls/.git/hooks/commit-msg.sample,sha256=H3TV6SkpebVz69WXQdRsuT_zkazdCD00C5Q3B1PZJDc,896
|
@@ -17,34 +17,41 @@ py2ls/.git/hooks/pre-receive.sample,sha256=pMPSuce7P9jRRBwxvU7nGlldZrRPz0ndsxAlI
|
|
17
17
|
py2ls/.git/hooks/prepare-commit-msg.sample,sha256=6d3KpBif3dJe2X_Ix4nsp7bKFjkLI5KuMnbwyOGqRhk,1492
|
18
18
|
py2ls/.git/hooks/push-to-checkout.sample,sha256=pT0HQXmLKHxt16-mSu5HPzBeZdP0lGO7nXQI7DsSv18,2783
|
19
19
|
py2ls/.git/hooks/update.sample,sha256=jV8vqD4QPPCLV-qmdSHfkZT0XL28s32lKtWGCXoU0QY,3650
|
20
|
-
py2ls/.git/index,sha256=
|
20
|
+
py2ls/.git/index,sha256=KnBXKHk0vrj4uZp4EYok6NChnC43qzhmQQ_3IQK9k2g,1391
|
21
21
|
py2ls/.git/info/exclude,sha256=ZnH-g7egfIky7okWTR8nk7IxgFjri5jcXAbuClo7DsE,240
|
22
|
-
py2ls/.git/logs/HEAD,sha256=
|
23
|
-
py2ls/.git/logs/refs/heads/main,sha256=
|
24
|
-
py2ls/.git/logs/refs/remotes/origin/HEAD,sha256=
|
25
|
-
py2ls/.git/logs/refs/remotes/origin/main,sha256=
|
22
|
+
py2ls/.git/logs/HEAD,sha256=KDy-71ywsGRlwiGKXUmYgZ-cS-GTBYMvaHQ8gM_T0JQ,2919
|
23
|
+
py2ls/.git/logs/refs/heads/main,sha256=KDy-71ywsGRlwiGKXUmYgZ-cS-GTBYMvaHQ8gM_T0JQ,2919
|
24
|
+
py2ls/.git/logs/refs/remotes/origin/HEAD,sha256=nd7egvRCnDKesgy_d766WNOlRDZae3agR_foSgGs1G0,6999
|
25
|
+
py2ls/.git/logs/refs/remotes/origin/main,sha256=cxI7Xz7qgDqX2lxmHw3FQkyfq8E4uvyefj2rxciWSQo,2584
|
26
|
+
py2ls/.git/objects/01/d5bd8065e6860c0bd23ff9fa57161806a099e1,sha256=hEQ8nqJnGsfFsuV5wc4cZas58rehXvT0v5ANx1zmMAY,584
|
27
|
+
py2ls/.git/objects/09/08da26de58c114225ad81f484b80bf5d351b34,sha256=NOyYvrJxATpK3aDdP1_stwkqOQRDwJn7DSy6isyKImE,925
|
26
28
|
py2ls/.git/objects/0b/409e1bc918277010f5679b402d1d1dda53e15c,sha256=y5S1XaGxJz1NXi-SPWjPC_NKIqqSbZv9oOg74MzBihY,156
|
27
29
|
py2ls/.git/objects/14/449a0e6ba4ea2f1a73acf63ef91c9c6193f9ed,sha256=PomZFmCUCQM1ii0wH-OJGSHLQCTqRtIwE5w3C0TtzSY,171
|
28
30
|
py2ls/.git/objects/15/a8e468aacfcb440e090020f36d0b985d45da23,sha256=xiRunMcN5I_B2hHgBUFupR-F0b8H_CQTmmAZG9XkZik,3215
|
29
31
|
py2ls/.git/objects/1a/b4585881a6a42889f01aa0cfe25fd5acfaf46f,sha256=iQsKMPNKUs4WQwhiLgXmG5V3xKyIgxmc13ZwbBATvhQ,165
|
32
|
+
py2ls/.git/objects/1c/3f92adda34344bcbbbf9d409c79855ae2aaea8,sha256=DkqkGgVpp0Zdj20Cfr_ptCecgY-inluZoOabSa7S1Is,170
|
30
33
|
py2ls/.git/objects/1d/fe9d9633b24ea560354f4f93d39c6e5f163ea0,sha256=mV_84wLqIitnSYmzfrNpTzwVP9AmksiRI0Fjltwl0Pg,8872
|
31
34
|
py2ls/.git/objects/24/6b368b986f758630c46dc02b7fa512b53422f7,sha256=sw7ERFCFu7m6fnURAqQfQ4GWShaARr-Vc6GRnlOPkxU,8512
|
32
35
|
py2ls/.git/objects/25/b796accd261b9135fd32a2c00785f68edf6c46,sha256=4ic5vOwEdfbGL8oARSVEeAnSoDs14-gggGZEL-61nYE,564
|
33
36
|
py2ls/.git/objects/30/a2f8da47ee947811dc8d993f5a06a45de374f4,sha256=u5W33_qNtTs1-U8Fardx-zB_udqKvuCm5kiw1mQGdsU,3218
|
37
|
+
py2ls/.git/objects/32/fd627b62fad7cf3b2f9e34ab9777126a0987ad,sha256=_QlClFT2799H_igDlGPr6Uz3SqoPN5v-hehesdIj18U,164
|
34
38
|
py2ls/.git/objects/36/b4a1b7403abc6c360f8fe2cb656ab945254971,sha256=X18sHo17gQTxusNptoILoWxSfU0ulrsZvbETlBtV5aY,2327
|
35
39
|
py2ls/.git/objects/36/e56a361f526eafa59c5235a5c990bf288b5f9c,sha256=7L1L-iqVvuufrlfEE2myD0-QnAPueFMySKetu08W-Pc,34216
|
36
40
|
py2ls/.git/objects/36/ef43e50009e59db11812c258846d9e38718173,sha256=0nwCwQSuQAdGyD2NfEK-_L12ydE9nGVKBXOfFq_Lndc,169
|
41
|
+
py2ls/.git/objects/39/7ead045fbbcfb17c62019eb18fe21ed05dbee5,sha256=3zM2AAtKWPfDVSy-prLogf1Z_RjkA6DwBBvN_M7pZqs,10409
|
37
42
|
py2ls/.git/objects/3b/bd972aa7ad680858f8dfbd0f7fcd97756f0d6f,sha256=MQWEzML3wbb4GixiHDCHrxgbXLQitrYDstT1plhmQSU,169
|
38
43
|
py2ls/.git/objects/3c/bbe5f4173d165127b9ad96119f1ec24c306ffc,sha256=S1BXemROYtzRaj5WXLPYnTmPTBQDKovMEN0GRLul-I4,33489
|
39
44
|
py2ls/.git/objects/3f/d6561300938afbb3d11976cf9c8f29549280d9,sha256=91oqbTWfUE1d_hT_1ptYmRUb5pOQ1X4oxQxpF6NXjKU,8501
|
40
45
|
py2ls/.git/objects/43/dbd49b2ee367c5434dd545e3b5795434f2ef0b,sha256=DAzt0dWp2KsuuImCKp7N9ia7KaCDNqwB-tYIx3Wf_c0,565
|
41
46
|
py2ls/.git/objects/48/a88fc5806305d0bb0755ee6801161b79696972,sha256=f3JStE39k_hPGE-WRwqZtDTjQkfOmBVb_6-ELBbScjI,203
|
47
|
+
py2ls/.git/objects/4f/7afb40dff2153d857fc85748c2eecb85125042,sha256=QnSXlNWzKLoMzDHNAiwe06vqJEQj9xu0q-9PvCUbtbM,39680
|
42
48
|
py2ls/.git/objects/50/08ddfcf53c02e82d7eee2e57c38e5672ef89f6,sha256=p0M2WLqiTe6X2FI_k5Aj0IEsE85jqLa58sVdmV8x1vU,255
|
43
49
|
py2ls/.git/objects/53/e0deb1cb4c2c606bced6e7f9a66b0fda60980d,sha256=muq6m7_XRSFPzypW-m9mhpKfsomCr4s7GfkgM3gh2pc,482344
|
44
50
|
py2ls/.git/objects/56/e4e8b2d5545e0256090f45aa8fc42c5fe067d0,sha256=VsjKo1biAzCV-iIfwCDTPzyfP63K43hdZqJpDP70Iik,529
|
45
51
|
py2ls/.git/objects/58/20a729045d4dc7e37ccaf8aa8eec126850afe2,sha256=3Pf6NS8OTK4EdHZGVeJ421BtK7w4WJncQDBauZI_wW4,34
|
46
52
|
py2ls/.git/objects/60/f273eb1c412d916fa3f11318a7da7a9911b52a,sha256=aJD9iF_LmYSrqDepXFBZKN1yMYbQczVkN_wnrDosBdI,5620
|
47
53
|
py2ls/.git/objects/61/570cec8c061abe74121f27f5face6c69b98f99,sha256=IQZi5MkbRu3ToRUPsRcXuh1Xa3pkAz_HDRCVhNL89ds,5753
|
54
|
+
py2ls/.git/objects/62/4488173ed2c8936fa5cea3cf5dd3f26a30b86e,sha256=gcoaeyK3Jo_yyqPclJ0jFA9wcsrVkD7tp4XvGDNGmpk,13225
|
48
55
|
py2ls/.git/objects/62/7c81b23b4e56e87b042b650b0103653cc9e34a,sha256=pv9wgBxnvJUFSrk9G7vApA6lnSykQSMJ4yXT7YnlSDU,167
|
49
56
|
py2ls/.git/objects/62/d90ccf8cbefdc2e4fd475e7c6f4f76e9fdf801,sha256=1L473QanNpnumCkE8tG6wtbvLqFtNeoagL9SJmasXNY,155
|
50
57
|
py2ls/.git/objects/64/27a4edff08f93d98f511418423f09f2ab90bcd,sha256=RyNngwk9fvdvvvywmNfllnim718fWNjVauH9U2y8Q2s,258
|
@@ -52,6 +59,7 @@ py2ls/.git/objects/69/13c452ca319f7cbf6a0836dc10a5bb033c84e4,sha256=NYLQQZTfd0ht
|
|
52
59
|
py2ls/.git/objects/6a/52e747a2b349b128d1490d9e896d2323818eb7,sha256=Qc_B3_xxlWmjooFu274r82b583uf_HpIpDBldr9fqVI,34966
|
53
60
|
py2ls/.git/objects/6b/7fde264d93a7a0986d394c46c7650d0ce2ab92,sha256=iIl0-RF0wd6BSEjzczgUyApxc899PbdTl04JbDn6_-Q,166
|
54
61
|
py2ls/.git/objects/6c/cebb29b7f3f5b0c889f6dadbf9ff066554587d,sha256=UylkFWAfhStNVQRQuC9CzpaWaT9uHCVs1mn7ecOma8I,609
|
62
|
+
py2ls/.git/objects/6d/ee29dbdcc84edeeacede105110446f3ccac963,sha256=-4Bi-tw0O-EbKxwJfMk_zHznNy0jvOK9G8hrXzz8AdA,9538
|
55
63
|
py2ls/.git/objects/71/36b2074a2754be8b58127d82250e5b37e3c373,sha256=cbVFQaBx0Q5QkZ1wQle-iIxNx14JxGSx3G8aQ7EbbAA,586
|
56
64
|
py2ls/.git/objects/78/3d4167bc95c9d2175e0df03ef1c1c880ba75ab,sha256=SK2QDjDBiDhVMG1I5p19g4RbEm2Rax7mYnxawmVZYxs,15523
|
57
65
|
py2ls/.git/objects/79/7ae089b2212a937840e215276005ce76881307,sha256=lQOKF2pb1JvipI3eT79X0-TuMGWsy1A-Yw4BCgKZNOM,33472
|
@@ -69,12 +77,16 @@ py2ls/.git/objects/b0/56be4be89ba6b76949dd641df45bb7036050c8,sha256=8Y7z30eNceBd
|
|
69
77
|
py2ls/.git/objects/b0/9cd7856d58590578ee1a4f3ad45d1310a97f87,sha256=82dx4hIdMpdcB64e5PU1s2gZFVkTvrj1cPwwJ_kasNU,4444
|
70
78
|
py2ls/.git/objects/b2/18e6a0f0f1c4df8cdefa9852058348abc713b7,sha256=hOQfdyzDZctjoge0-pAcEDel5XHVPNfOtrMNyFPUOIE,564
|
71
79
|
py2ls/.git/objects/b5/61831c7dce8ea51e7ee6b6fa35745f14d8242d,sha256=wUqxlKjLN1vOUj2tkYStado64QewdcF3CHlSICds1ik,34415
|
80
|
+
py2ls/.git/objects/b7/2c9e75ab7d0afe594664650aa8f6c772f5ac64,sha256=dyeWYp22wgZSCE7D3F43N76ehCDTsbMJcSMJRW3VbDI,65
|
81
|
+
py2ls/.git/objects/bb/81ccc0513f18fc160b54a82861e9a80d23f4f6,sha256=WrBnpacpm4kOcVCYoWgPO8MqOAi0ZeHaxekPT3DxpCk,587
|
72
82
|
py2ls/.git/objects/bb/934eb33bc1a8b85630bf680caffd99560c1b8f,sha256=ggehjexUsWlskHJvHxW7u6U0otB0OCItmIZdT9O-3OU,9670
|
73
83
|
py2ls/.git/objects/c1/20fc812b9ad311c34a3608512d6a9d976bb48e,sha256=q-WAKugB-_-g7w0Mlw6oyTBaXQ_Qd7BdLatrDiYN7Wc,156
|
74
84
|
py2ls/.git/objects/c4/cba65f1163661999ee4b8ed23342b63bc1300c,sha256=rwSdKt-C98nUQ_B-7imY4fYRYmn29MQc4SIu9wruHeo,566
|
75
85
|
py2ls/.git/objects/c6/7f17e5707313600efcb85e9a3fedea35dba591,sha256=TL7rDIWiaWlk8iIwqPst7St5Xr2otPs-vp17GPlET7o,565
|
86
|
+
py2ls/.git/objects/cd/822b3574a88ebdd1ed82fd6983f37e626d52b4,sha256=MJbPJ-8vpfVTUMhzyzTp5qGmZYgsgrG-7nwwzDdODlQ,617
|
76
87
|
py2ls/.git/objects/cf/0c0d9c6fb09473aaeb7f7e2edbd770c3f2ef3d,sha256=T_nV0GrgpVu3mOJ4fYcCW98oCunzgqy0DnSX0luy04Q,183
|
77
88
|
py2ls/.git/objects/d6/9ab1c4aadf279936dd778e8346ba60f74705b6,sha256=WcfdSMKqfiWT5TOWVUcDj0XDaD2hYxDnyIRNlYGutL8,34976
|
89
|
+
py2ls/.git/objects/d8/4688b54c0040a30976b3a6540bc47adf7ce680,sha256=1gJp1iTVAooc5PZZsiIj215-J1RtJ-_zy22_9jZ8jAY,160
|
78
90
|
py2ls/.git/objects/d9/005f2cc7fc4e65f14ed5518276007c08cf2fd0,sha256=IJIoz93V7pf9yx43U1JdN8gBq_LWtw8A9Z2YMPnq_B0,1450
|
79
91
|
py2ls/.git/objects/d9/c2403fd166ce791b4e9d0c6792ed8342c71fcd,sha256=uD7BsKdrmN-9FStTpwsRWh-XxVXeDsV4dGjFkaMIIs8,170
|
80
92
|
py2ls/.git/objects/d9/dfa5aee51e92a541b707e8e7baea6f06deff98,sha256=jMdhZ1i_L5q_UgjOtjLN15PCSCz3pE51FhD3z74ZUr8,163
|
@@ -84,28 +96,32 @@ py2ls/.git/objects/df/e0770424b2a19faf507a501ebfc23be8f54e7b,sha256=vCdlxwEidekh
|
|
84
96
|
py2ls/.git/objects/e3/1356f90ea6dd0577b5e0b40b206319adcbf085,sha256=I9_QNwmmtoqSwq29Ixdfv_PgF2x14u2M6sX1eQumwoY,161
|
85
97
|
py2ls/.git/objects/e3/5a4dafc50850cacac7bf76c56db2715cbda2c4,sha256=GAcBj3YSEbm6tm7fGD6al16uBo8LtEtjZ2Hi-UgIsUg,3290
|
86
98
|
py2ls/.git/objects/e9/391ffe371f1cc43b42ef09b705d9c767c2e14f,sha256=RWTy2n8L2XxZQknBFyPczA0Aa_4gSG_Ybcr8e8v4ccc,10264
|
99
|
+
py2ls/.git/objects/f1/e50757fddc28b445545dc7e2759b54cdd0f42e,sha256=2NG4lzk2IPOZfJ4tRHvxla63yQTcY_YTOprG1tzK-IY,40554
|
87
100
|
py2ls/.git/objects/f4/b64d3107b39e3ad6f540c6607004ea34e6c024,sha256=0egAtqc0x8hc7U1z91tIjcRhSd_BT2a_gxZxo_7NTJA,564
|
88
101
|
py2ls/.git/objects/f7/c98ba5c2f903e603b1f5e63d49fbc8a43815cc,sha256=tYbi3A7irrIPB_11bwItuof0Vc9a0MDuLFMNAzRsG3A,33467
|
89
102
|
py2ls/.git/objects/fa/147e6bb78a2e8db241d231295fd7f1ed061af8,sha256=G9pg5LXv7AdxnPIQsTm2AF3Un314dLRJQYwxmZem9rQ,574
|
90
103
|
py2ls/.git/objects/fc/292e793ecfd42240ac43be407023bd731fa9e7,sha256=hGIYoxKWNT3IPwk3DE4l3FLBbUYF-kXcHcx7KrH9uS0,1971
|
91
|
-
py2ls/.git/refs/heads/main,sha256=
|
104
|
+
py2ls/.git/refs/heads/main,sha256=k6rcF3ygBr7oPi2hdbKsSuf8k1tlLGgqVho63xNgiuY,41
|
92
105
|
py2ls/.git/refs/remotes/origin/HEAD,sha256=K7aiSqD8bEhBAPXVGim7rYQc0sdV9dk_qiBOXbtOsrQ,30
|
93
|
-
py2ls/.git/refs/remotes/origin/main,sha256=
|
106
|
+
py2ls/.git/refs/remotes/origin/main,sha256=k6rcF3ygBr7oPi2hdbKsSuf8k1tlLGgqVho63xNgiuY,41
|
94
107
|
py2ls/.gitattributes,sha256=Gh2-F2vCM7SZ01pX23UT8pQcmauXWfF3gwyRSb6ZAFs,66
|
95
108
|
py2ls/.gitignore,sha256=y7GvbD_zZkjPVVIue8AyiuFkDMuUbvMaV65Lgu89To8,2763
|
96
109
|
py2ls/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
|
97
110
|
py2ls/README.md,sha256=CwvJWAnSXnCnrVHlnEbrxxi6MbjbE_MT6DH2D53S818,11572
|
98
|
-
py2ls/__init__.py,sha256=
|
111
|
+
py2ls/__init__.py,sha256=47TrrzqhyLX7Y8xNnCfjTWQPlhlSsLwHDUT5OkEQ9Z0,239
|
99
112
|
py2ls/brain_atlas.py,sha256=w1o5EelRjq89zuFJUNSz4Da8HnTCwAwDAZ4NU4a-bAY,5486
|
100
113
|
py2ls/correlators.py,sha256=RbOaJIPLCHJtUm5SFi_4dCJ7VFUPWR0PErfK3K26ad4,18243
|
101
|
-
py2ls/
|
114
|
+
py2ls/data/.DS_Store,sha256=1lFlJ5EFymdzGAUAaI30vcaaLHt3F1LwpG7xILf9jsM,6148
|
115
|
+
py2ls/data/db2ls_sql_chtsht.json,sha256=ls9d7Sm8TLeujanWHfHlWhU85Qz1KnAizO_9X3wUH7E,6933
|
116
|
+
py2ls/data/lang_code_iso639.json,sha256=qZiU7H2RLJjDMXK22C-jhwzLJCI5vKmampjB1ys4ek4,2157
|
117
|
+
py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
|
102
118
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
103
|
-
py2ls/ips.py,sha256=
|
104
|
-
py2ls/netfinder.py,sha256=
|
119
|
+
py2ls/ips.py,sha256=I8pW4SJ11Y4okThmJmvWDdFmMa5XZR7MOhUWkqsEscA,140502
|
120
|
+
py2ls/netfinder.py,sha256=ZsLWGYMeRuGvxj2nqE0Z8ANoaVl18Necfw0HQfh2q7I,45548
|
105
121
|
py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
|
106
122
|
py2ls/sleep_events_detectors.py,sha256=36MCuRrpurn0Uvzpo3p3b3_JlVsRNHSWCXbJxCGM3mg,51546
|
107
|
-
py2ls/translator.py,sha256=
|
123
|
+
py2ls/translator.py,sha256=6S7MmTZmjj8NljVmj0W5uEauu4ePxso3AMf2LvGVRQA,30516
|
108
124
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
109
|
-
py2ls-0.1.4.
|
110
|
-
py2ls-0.1.4.
|
111
|
-
py2ls-0.1.4.
|
125
|
+
py2ls-0.1.4.9.dist-info/METADATA,sha256=TaiklHUvW4uVWJ2_hyDwiZL76ALa-7pBW5h2fE5koTg,17943
|
126
|
+
py2ls-0.1.4.9.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
127
|
+
py2ls-0.1.4.9.dist-info/RECORD,,
|
py2ls/dbhandler.py
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
import sqlite3
|
2
|
-
import time
|
3
|
-
|
4
|
-
class dbhandler:
|
5
|
-
def __init__(self, db_path):
|
6
|
-
self.db_path = db_path
|
7
|
-
|
8
|
-
def execute_query(self, query, params=None, retries=2, delay=1):
|
9
|
-
for attempt in range(retries):
|
10
|
-
try:
|
11
|
-
conn = sqlite3.connect(self.db_path)
|
12
|
-
c = conn.cursor()
|
13
|
-
if params:
|
14
|
-
c.execute(query, params)
|
15
|
-
else:
|
16
|
-
c.execute(query)
|
17
|
-
conn.commit()
|
18
|
-
conn.close()
|
19
|
-
return
|
20
|
-
except sqlite3.OperationalError as e:
|
21
|
-
if "database is locked" in str(e) and attempt < retries - 1:
|
22
|
-
print(f"Database is locked, retrying in {delay} seconds...")
|
23
|
-
time.sleep(delay)
|
24
|
-
else:
|
25
|
-
print(f"Error executing query: {e}")
|
26
|
-
break
|
27
|
-
|
28
|
-
def create_table(self, table_definition):
|
29
|
-
self.execute_query(table_definition)
|
30
|
-
print(f"Table created with definition: {table_definition}")
|
31
|
-
|
32
|
-
def insert_data(self, table, columns, data):
|
33
|
-
placeholders = ', '.join(['?' for _ in data])
|
34
|
-
query = f"INSERT INTO {table} ({', '.join(columns)}) VALUES ({placeholders})"
|
35
|
-
self.execute_query(query, data)
|
36
|
-
print(f"Data inserted into {table}: {data}")
|
37
|
-
|
38
|
-
def select_data(self, table, columns='*', where_clause=None, where_params=None):
|
39
|
-
query = f"SELECT {', '.join(columns)} FROM {table}"
|
40
|
-
if where_clause:
|
41
|
-
query += f" WHERE {where_clause}"
|
42
|
-
try:
|
43
|
-
conn = sqlite3.connect(self.db_path)
|
44
|
-
c = conn.cursor()
|
45
|
-
if where_params:
|
46
|
-
c.execute(query, where_params)
|
47
|
-
else:
|
48
|
-
c.execute(query)
|
49
|
-
rows = c.fetchall()
|
50
|
-
conn.close()
|
51
|
-
return rows
|
52
|
-
except sqlite3.OperationalError as e:
|
53
|
-
print(f"Error selecting data: {e}")
|
54
|
-
return None
|
55
|
-
|
56
|
-
def update_data(self, table, updates, where_clause, where_params):
|
57
|
-
update_clause = ', '.join([f"{col} = ?" for col in updates.keys()])
|
58
|
-
params = list(updates.values()) + list(where_params)
|
59
|
-
query = f"UPDATE {table} SET {update_clause} WHERE {where_clause}"
|
60
|
-
self.execute_query(query, params)
|
61
|
-
print(f"Data updated in {table} where {where_clause}: {updates}")
|
62
|
-
|
63
|
-
def delete_data(self, table, where_clause, where_params):
|
64
|
-
query = f"DELETE FROM {table} WHERE {where_clause}"
|
65
|
-
self.execute_query(query, where_params)
|
66
|
-
print(f"Data deleted from {table} where {where_clause}")
|
67
|
-
|
68
|
-
# Example usage
|
69
|
-
if __name__ == "__main__":
|
70
|
-
db = dbhandler("/Users/macjianfeng/Dropbox/github/python/xample_dbhandler/data/example.db")
|
71
|
-
|
72
|
-
# Create table
|
73
|
-
create_table_sql = """CREATE TABLE IF NOT EXISTS tab (
|
74
|
-
row TEXT PRIMARY KEY,
|
75
|
-
content TEXT)"""
|
76
|
-
db.create_table(create_table_sql)
|
77
|
-
|
78
|
-
# Insert data
|
79
|
-
db.insert_data("tab", ["row", "content"], ["row1", "This is a row"])
|
80
|
-
|
81
|
-
# Select data
|
82
|
-
rows = db.select_data("tab")
|
83
|
-
print("Selected rows:", rows)
|
84
|
-
|
85
|
-
# Update data
|
86
|
-
db.update_data("tab", {"content": "Updated content"}, "row = ?", ["row1"])
|
87
|
-
|
88
|
-
# Select data again to see the update
|
89
|
-
rows = db.select_data("tab")
|
90
|
-
print("Selected rows after update:", rows)
|
91
|
-
|
92
|
-
# Delete data
|
93
|
-
db.delete_data("tab", "row = ?", ["row1"])
|
94
|
-
|
95
|
-
# Select data again to see the deletion
|
96
|
-
rows = db.select_data("tab")
|
97
|
-
print("Selected rows after deletion:", rows)
|