20211012のNode.jsに関する記事は2件です。

DeepL API の使用方法

auth_key と text, source_lang, target_lang を指定して GET or POST するだけ 参考: https://www.deepl.com/docs-api/introduction/ シェルスクリプト deepl.sh #!/bin/sh DEEPL_API_URL="https://api-free.deepl.com/v2/translate" YOUR_API_KEY="__DEEPL_API_KEY_HERE__" SOURCE_TEXT=" I'm a lumberjack and I'm OK. I sleep at night, I work during the day. He's a lumberjack and he's OK. He sleeps all night and he works all day. I cut down trees, I eat my lunch. I go to the lavatory. On Wednesdays I go shopping and have buttered scones for tea. " curl -s ${DEEPL_API_URL} \ -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "auth_key=${YOUR_API_KEY}" \ -d "text=${SOURCE_TEXT}" \ -d "source_lang=EN" \ -d "target_lang=JA" \ | jq .translations[].text Python deepl.py import requests DEEPL_API_URL = 'https://api-free.deepl.com/v2/translate' YOUR_API_KEY = '__DEEPL_API_KEY_HERE__' SOURCE_TEXT = """ I'm a lumberjack and I'm OK. I sleep at night, I work during the day. He's a lumberjack and he's OK. He sleeps all night and he works all day. I cut down trees, I eat my lunch. I go to the lavatory. On Wednesdays I go shopping and have buttered scones for tea. """ params = { "auth_key": YOUR_API_KEY, "text": SOURCE_TEXT, "source_lang": 'EN', "target_lang": 'JA' } request = requests.post(DEEPL_API_URL, data=params) result = request.json() print(result["translations"][0]["text"]) Node.js deepl.js const request = require('request'); const deepl_api_url = 'https://api-free.deepl.com/v2/translate' const your_api_key = '__DEEPL_API_KEY_HERE__'; const source_text = ` I'm a lumberjack and I'm OK. I sleep at night, I work during the day. He's a lumberjack and he's OK. He sleeps all night and he works all day. I cut down trees, I eat my lunch. I go to the lavatory. On Wednesdays I go shopping and have buttered scones for tea. `; const params = { url: deepl_api_url, method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, form: { auth_key: your_api_key, text: source_text, source_lang: 'EN', target_lang: 'JA' }, json: true } request.post(params, function(error, response, result){ console.log(result.translations[0].text); }); PHP deepl.php <?php $deepl_api_url = 'https://api-free.deepl.com/v2/translate'; $your_api_key = '__DEEPL_API_KEY_HERE__'; $source_text = " I'm a lumberjack and I'm OK. I sleep at night, I work during the day. He's a lumberjack and he's OK. He sleeps all night and he works all day. I cut down trees, I eat my lunch. I go to the lavatory. On Wednesdays I go shopping and have buttered scones for tea. "; $header = [ 'Content-Type: application/x-www-form-urlencoded', ]; $content = [ 'auth_key' => $your_api_key, 'text' => $source_text, 'source_lang' => 'EN', 'target_lang' => 'JA', ]; $params = [ 'http' => [ 'method' => 'POST', 'header' => implode("\r\n", $header), 'content' => http_build_query($content, '', '&'), ] ]; $request = file_get_contents( $deepl_api_url, false, stream_context_create($params) ); $result = json_decode($request); echo $result->translations[0]->text; 実行結果 私は木こりですが、大丈夫ですよ。 夜は寝て、昼は働く。 彼は木こりであり、彼はOKだ。 彼は夜も寝るし、昼も働く。 木を切って、お昼を食べて。 お手洗いにも行く。 水曜日には買い物に行き、紅茶にバター入りのスコーンを食べる。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【node・git】リリース操作周辺

初書:2021/10/12 mac : 11.6 node:v16.6.1 前書き node.jsでアプリケーションをリリースする際によく調べ直すことが多い項目をメモしておく。 package.jsonのバージョンを更新する 参考サイト:npm versionコマンドで出来ること。 - Qiita % npm version xxxでパッケージのバージョンを更新することができる xxxは、 majorで1.0.0 minorで0.1.0 patchで0.0.1 の部分を更新する。 また、先頭にpreをつけることで、各部分を更新した上で、x.x.x-0と、最後に-0を追加する。 また-0は、prereleaseで更新することができる。 タグをgithubにpushする 参考サイト:git tagの使い方まとめ - Qiita 上記のコマンドを実行すると、自動的にコミットされるが、そのコミットにタグが付けられる。 ただそのタグは、単にpushしても何故かgithubに行かない1 そのため、タグだけ別途pushする必要がある。 % git push origin タグ名 これでgithub側にもタグが共有される。 終わりに 他にも何か追加するかも。 vscodeの機能でpushしたから?その辺りは検証していない。 ↩
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む