MbNextT1me 2 роки тому
батько
коміт
8dab061e97
5 змінених файлів з 130 додано та 0 видалено
  1. 19 0
      python/in.txt
  2. 54 0
      python/main.py
  3. 19 0
      python/outputEN
  4. 19 0
      python/outputFR
  5. 19 0
      python/outputJA

+ 19 - 0
python/in.txt

@@ -0,0 +1,19 @@
+Жили-были старик со старухой.
+Вот и говорит старик старухе:
+— Поди-ка, старуха, по коробу поскреби, по сусеку помети, не наскребешь ли муки на колобок.
+Взяла старуха крылышко, по коробу поскребла, по сусеку помела и наскребла муки горсти две.
+Замесила муку на сметане, состряпала колобок, изжарила в масле и на окошко студить положила.
+Колобок полежал, полежал, взял да и покатился — с окна на лавку, с лавки на пол, пó полу к двери, прыг через порог — да в сени, из сеней на крыльцо, с крыльца на двор, со двора за ворота, дальше и дальше.
+Катится Колобок по дороге, навстречу ему Заяц:
+— Колобок, Колобок, я тебя съем!
+— Не ешь меня, Заяц, я тебе песенку спою:
+
+Я Колобок, Колобок,
+Я по коробу скребен,
+По сусеку метен,
+На сметане мешон
+Да в масле пряжон,
+На окошке стужон.
+Я от дедушки ушел,
+Я от бабушки ушел,
+От тебя, зайца, подавно уйду!

+ 54 - 0
python/main.py

@@ -0,0 +1,54 @@
+import requests
+import argparse
+import json
+import sys
+import re
+
+# Парсим командную строку
+parser = argparse.ArgumentParser(description="Translator's manual!")
+parser.add_argument("--file", default=1, type=str, help="Файл, который вы хотите перевести")
+parser.add_argument("--lan", default=1, type=str, help="Выберите язык для перевода")
+parser.add_argument("--out", default="output.txt", type=str, help="Выберите файл для вывода")
+
+# Задаём аргументы
+args = parser.parse_args()
+text = args.file
+toLan = args.lan
+output = args.out
+
+# Проверка на ввод
+if text == 1 or toLan == 1:
+    print("Ошибка! Неверно заданы аргументы!")
+    sys.exit()
+
+# Считываем файл
+with open(text, 'r', encoding="utf-8") as file:
+    data = file.read()
+
+# Делаем запрос
+headers = {
+    'Ocp-Apim-Subscription-Key': '9bf007a897f54e4a94203f8aa88cd2b1',
+    'Ocp-Apim-Subscription-Region': 'westeurope',
+    'Content-type': 'application/json'
+}
+url = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=' + toLan
+body = [{
+    'Text': data
+}]
+
+# Проверяем, выполнен ли запрос
+try:
+    response = requests.post(url, headers=headers, json=body)
+except Exception:
+    print("Ошибка! Запрос не был выполнен!")
+    sys.exit()
+
+# Если запрос выполнен
+result = response.json()
+
+# Запись в файл
+f = open(output, 'w', encoding='utf-8')
+f.write(result[0]['translations'][0]['text'])
+f.close()
+
+print("\nПеревод успешно записан в файл!")

+ 19 - 0
python/outputEN

@@ -0,0 +1,19 @@
+Once upon a time there was an old man with an old woman.
+So the old man says to the old woman:
+- Podi-ka, old woman, scrape through the box, mark the soucock, will you scrape the flour into a kolobok.
+The old woman took a wing, scraped it through the box, swept it through the bottom and scraped the flour of a handful of two.
+I kneaded the flour on sour cream, concocted the kolobok, fried it in oil and put it on the window.
+Kolobok lay down, lay down, took yes and rolled - from window to bench, from bench to floor, floor to door, jumped over the threshold - yes in the canopy, from the canopy to the porch, from the porch to the yard, from the yard to the gate, further and further.
+Kolobok rolls along the road, towards him hare:
+- Kolobok, Kolobok, I'll rent you!
+"Don't eat me, Hare, I'll sing you a song:
+
+I'm Kolobok, Kolobok,
+I'm a box scraper,
+On the susek meten,
+On sour cream meshon
+Yes in the oil of the buckle,
+There is a stuzhon on the window.
+I left my grandfather,
+I left my grandmother,
+I'll leave you, hare!

+ 19 - 0
python/outputFR

@@ -0,0 +1,19 @@
+Il était une fois un vieil homme avec une vieille femme.
+Alors le vieil homme dit à la vieille femme:
+- Podi-ka, vieille femme, gratte à travers la boîte, marque le soucock, grattez-vous la farine dans un kolobok.
+La vieille femme prit une aile, la gratta à travers la boîte, la balaya par le fond et gratta la farine d’une poignée de deux.
+J’ai pétri la farine sur de la crème sure, concocté le kolobok, frit dans l’huile et mis sur la fenêtre.
+Kolobok s’est allongé, s’est allongé, a pris oui et a roulé - de la fenêtre au banc, du banc au sol, du sol à la porte, a sauté par-dessus le seuil - oui dans la verrière, de la verrière au porche, du porche à la cour, de la cour à la porte, de plus en plus loin.
+Kolobok roule le long de la route, vers lui lièvre :
+- Kolobok, Kolobok, je vais te louer !
+« Ne me mange pas, Lièvre, je vais te chanter une chanson:
+
+Je suis Kolobok, Kolobok,
+Je suis un grattoir de boîtes,
+Sur le susek meten,
+Sur la crème sure meshon
+Oui dans l’huile de la boucle,
+Il y a un stuzhon sur la fenêtre.
+J’ai quitté mon grand-père,
+J’ai quitté ma grand-mère,
+Je te laisse, lièvre !

+ 19 - 0
python/outputJA

@@ -0,0 +1,19 @@
+昔々、おばあさんとおばあさんがいました。
+だから、老人は老婦人に言う:
+- ポディカ、老婦人は、箱をこすり、スーコックをマークし、あなたはコロボックに小麦粉を削ります。
+老婦人は翼を取り、箱を通してそれを削り取り、底を掃いて、一握りの小麦粉を削った。
+私はサワークリームで小麦粉を練り、コロボクを作り、油で揚げて窓に置いた。
+コロボクは横になり、横になり、はい、はい、転がった - 窓からベンチへ、ベンチから床へ、床からドアに、しきい値を飛び越えました - はい、キャノピー、キャノピーからポーチまで、ポーチから庭まで、さらにさらに。
+コロボクは、彼のヘアに向かって、道路に沿って転がります:
+- コロボク、コロボク、私はあなたを借りる!
+「私を食べないで、ヘア、私はあなたに歌を歌います:
+
+私はコロボク、コロボク、
+私は箱のスクレーパーです。
+セセクメテンで、
+サワークリームメソンで
+はい、バックルのオイルで、
+窓にストゥゾンがあります。
+私は祖父を置き去りにし、
+私は祖母を置き去りにし、
+お前を置き去りにするぞ!