rewited funcs
This commit is contained in:
@@ -1,44 +1,20 @@
|
||||
#!/usr/bin/pyhton3
|
||||
import requests
|
||||
import time
|
||||
from random import randint
|
||||
|
||||
|
||||
|
||||
def translate(_input, lang='RU'):
|
||||
url = "https://www2.deepl.com/jsonrpc"
|
||||
_id = randint(10000000, 99999999)
|
||||
def translate(_input, lang='ru'):
|
||||
url = "http://192.168.8.3:5000/translate"
|
||||
|
||||
r = requests.post(
|
||||
url,
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"method": "LMT_handle_jobs",
|
||||
"params": {
|
||||
"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,
|
||||
"commonJobParams": {},
|
||||
"timestamp": int(round(time.time() * 1000))
|
||||
},
|
||||
"id": _id
|
||||
}
|
||||
)
|
||||
try:
|
||||
return r.json()['result']['translations'][0]['beams'][0]['postprocessed_sentence']
|
||||
except:
|
||||
print(r.json())
|
||||
|
||||
"q": _input,
|
||||
"source": "en",
|
||||
"target": lang,
|
||||
},
|
||||
headers={"Content-Type": "application/json"}
|
||||
|
||||
)
|
||||
return r.json()['translatedText']
|
||||
|
||||
|
||||
|
||||
|
||||
55
main.py
55
main.py
@@ -1,31 +1,24 @@
|
||||
#!/usr/bin/pyhton3
|
||||
import os
|
||||
import re
|
||||
from fnmatch import fnmatch
|
||||
|
||||
_path = r'C:/Users/riksl/PycharmProjects/weapon-project-extended/data/scripts/'
|
||||
|
||||
name = "weapongenerator.lua"
|
||||
from lib.translate import translate
|
||||
|
||||
|
||||
def _lister(_path) -> list:
|
||||
_list: list = []
|
||||
try:
|
||||
pattern = "*.lua"
|
||||
def scan_files(path) -> list:
|
||||
"""
|
||||
Scans dirs and subdirs in PATH to gind *.lua files
|
||||
: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):
|
||||
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
|
||||
return list_files
|
||||
|
||||
|
||||
print(_path)
|
||||
print(_lister(_path))
|
||||
# name = "weapongenerator.lua"
|
||||
|
||||
|
||||
def parsing_file(f):
|
||||
@@ -42,10 +35,24 @@ def parsing_file(f):
|
||||
return _to_translate
|
||||
|
||||
|
||||
for _str in parsing_file(name):
|
||||
test = re.findall('= "(.*[^/])(?: /\* (.*)\*/)?"%_[t|T]', _str)
|
||||
# print(test)
|
||||
def pars_file(name: str) -> list:
|
||||
"""
|
||||
:param name: name of file
|
||||
:return:
|
||||
"""
|
||||
list_to_translate: list = []
|
||||
for _str in parsing_file(name):
|
||||
string_to_translate = re.findall('= "(.*[^/])(?: /\* (.*)\*/)?"%_[t|T]', _str)
|
||||
list_to_translate.append(string_to_translate)
|
||||
return list_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