rewited funcs
This commit is contained in:
@@ -1,44 +1,20 @@
|
|||||||
#!/usr/bin/pyhton3
|
#!/usr/bin/pyhton3
|
||||||
import requests
|
import requests
|
||||||
import time
|
|
||||||
from random import randint
|
|
||||||
|
|
||||||
|
|
||||||
|
def translate(_input, lang='ru'):
|
||||||
def translate(_input, lang='RU'):
|
url = "http://192.168.8.3:5000/translate"
|
||||||
url = "https://www2.deepl.com/jsonrpc"
|
|
||||||
_id = randint(10000000, 99999999)
|
|
||||||
|
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
url,
|
url,
|
||||||
json={
|
json={
|
||||||
"jsonrpc": "2.0",
|
"q": _input,
|
||||||
"method": "LMT_handle_jobs",
|
"source": "en",
|
||||||
"params": {
|
"target": lang,
|
||||||
"jobs": [{
|
|
||||||
"kind": "default",
|
|
||||||
"raw_en_sentence": _input,
|
|
||||||
"raw_en_context_before": [],
|
|
||||||
"raw_en_context_after": [],
|
|
||||||
"preferred_num_beams": 4,
|
|
||||||
"quality": "fast"
|
|
||||||
}],
|
|
||||||
"lang": {
|
|
||||||
"user_preferred_langs": [lang],
|
|
||||||
"source_lang_user_selected": "auto",
|
|
||||||
"target_lang": "RU"
|
|
||||||
},
|
},
|
||||||
"priority": -1,
|
headers={"Content-Type": "application/json"}
|
||||||
"commonJobParams": {},
|
|
||||||
"timestamp": int(round(time.time() * 1000))
|
|
||||||
},
|
|
||||||
"id": _id
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
try:
|
return r.json()['translatedText']
|
||||||
return r.json()['result']['translations'][0]['beams'][0]['postprocessed_sentence']
|
|
||||||
except:
|
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
53
main.py
53
main.py
@@ -1,31 +1,24 @@
|
|||||||
#!/usr/bin/pyhton3
|
#!/usr/bin/pyhton3
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from fnmatch import fnmatch
|
from lib.translate import translate
|
||||||
|
|
||||||
_path = r'C:/Users/riksl/PycharmProjects/weapon-project-extended/data/scripts/'
|
|
||||||
|
|
||||||
name = "weapongenerator.lua"
|
|
||||||
|
|
||||||
|
|
||||||
def _lister(_path) -> list:
|
def scan_files(path) -> list:
|
||||||
_list: list = []
|
"""
|
||||||
try:
|
Scans dirs and subdirs in PATH to gind *.lua files
|
||||||
pattern = "*.lua"
|
:param path: set path to scan
|
||||||
|
:return: list of files in dir and subdir
|
||||||
|
"""
|
||||||
|
list_files = []
|
||||||
|
for root, dirs, files in os.walk(path):
|
||||||
|
for file in files:
|
||||||
|
if '.lua' in file: list_files.append(f'{root}/{file}')
|
||||||
|
|
||||||
for path, subdirs, files in os.scandir(_path):
|
return list_files
|
||||||
for name in files:
|
|
||||||
if fnmatch(name, pattern):
|
|
||||||
print(os.path.join(path, name))
|
|
||||||
_list.extend(f"{path}/{name}")
|
|
||||||
break
|
|
||||||
return sorted(_list)
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
print(_path)
|
# name = "weapongenerator.lua"
|
||||||
print(_lister(_path))
|
|
||||||
|
|
||||||
|
|
||||||
def parsing_file(f):
|
def parsing_file(f):
|
||||||
@@ -42,10 +35,24 @@ def parsing_file(f):
|
|||||||
return _to_translate
|
return _to_translate
|
||||||
|
|
||||||
|
|
||||||
|
def pars_file(name: str) -> list:
|
||||||
|
"""
|
||||||
|
:param name: name of file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
list_to_translate: list = []
|
||||||
for _str in parsing_file(name):
|
for _str in parsing_file(name):
|
||||||
test = re.findall('= "(.*[^/])(?: /\* (.*)\*/)?"%_[t|T]', _str)
|
string_to_translate = re.findall('= "(.*[^/])(?: /\* (.*)\*/)?"%_[t|T]', _str)
|
||||||
# print(test)
|
list_to_translate.append(string_to_translate)
|
||||||
|
return list_to_translate
|
||||||
|
|
||||||
|
|
||||||
def all_to_translate():
|
def all_to_translate():
|
||||||
pass
|
_files = scan_files(r'C:/Users/riksl/PycharmProjects/weapon-project-extended/')
|
||||||
|
print(_files)
|
||||||
|
# for _file in _files:
|
||||||
|
# _strings = pars_file(_file)
|
||||||
|
# print(_strings)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
all_to_translate()
|
||||||
|
|||||||
Reference in New Issue
Block a user