Last active
November 6, 2024 15:10
-
-
Save itsNikolay/01c66e1b300de01ee97f20df39a8e78a to your computer and use it in GitHub Desktop.
https://turgenev.ashmanov.com/ API request for js, ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs/promises'; | |
import path from 'path'; | |
import fetch from 'node-fetch'; | |
import open from 'open'; | |
const checkText = async (apiKey, apiType, text = null, url = null, tbclass = null, more = 0) => { | |
const uri = "https://turgenev.ashmanov.com/"; | |
// Формируем параметры запроса | |
const params = new URLSearchParams({ | |
api: apiType, | |
key: apiKey, | |
more, | |
...(text && { text }), | |
...(url && { url }), | |
...(tbclass && { tbclass }), | |
}); | |
try { | |
// Выполняем POST-запрос с использованием fetch | |
const response = await fetch(uri, { | |
method: 'POST', | |
body: params, | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
}); | |
// Обработка ответа | |
if (!response.ok) { | |
throw new Error(`Ошибка сети: ${response.status} ${response.statusText}`); | |
} | |
const result = await response.json(); // Получаем JSON из ответа | |
console.log('Результат проверки:', JSON.stringify(result, null, 2)); | |
if (result.error) { | |
console.error(`Ошибка: ${result.error}`); | |
} else { | |
console.log(`Ссылка: https://turgenev.ashmanov.com/?t=${result.link}`); | |
await open(`https://turgenev.ashmanov.com/?t=${result.link}`); | |
} | |
} catch (error) { | |
console.error(`Ошибка: ${error.message}`); | |
} | |
}; | |
// Пример использования | |
const apiKey = 'KEY'; // Замените на ваш реальный API-ключ | |
const apiType = 'risk'; // Например, 'risk' или 'style' | |
// Укажите текст или URL, но не оба одновременно | |
const run = async () => { | |
const textFilePath = path.join(process.cwd(), 'text.txt'); // Путь к файлу text.txt | |
const text = (await fs.readFile(textFilePath, 'utf8')).replace(/\n/g, "<br />"); | |
const url = null; // Например, "https://somesite.ru/nazvanie-razdela/stranica" | |
const tbclass = '.content'; // CSS-селектор для URL | |
const more = 1; // Установите 1 для детализированного ответа | |
await checkText(apiKey, apiType, text, url, tbclass, more); | |
}; | |
run().catch(console.error); | |
// Использование: | |
// 1. создать файл text.txt с проверяемым текстом | |
// 2. запустить команду `node turgenev.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'json' | |
def check_text(api_key, api_type, text: nil, url: nil, tbclass: nil, more: 0) | |
uri = URI("https://turgenev.ashmanov.com/") | |
# Формируем параметры запроса | |
params = { | |
'api' => api_type, | |
'key' => api_key, | |
'more' => more | |
} | |
params['text'] = text if text | |
params['url'] = url if url | |
params['tbclass'] = tbclass if tbclass | |
# Выполняем POST-запрос | |
response = Net::HTTP.post_form(uri, params) | |
# Обработка ответа | |
if response.is_a?(Net::HTTPSuccess) | |
result = JSON.parse(response.body) | |
if result['error'] | |
puts "Ошибка: #{result['error']}" | |
else | |
puts "Результат проверки: #{result}" | |
# pretty_print(result) | |
puts JSON.pretty_generate(result) | |
puts "Ссылка: https://turgenev.ashmanov.com/?t=#{result['link']}" | |
system("open https://turgenev.ashmanov.com/?t=#{result['link']}") | |
end | |
else | |
puts "Ошибка сети: #{response.message}" | |
end | |
end | |
# Пример использования | |
api_key = 'YOUR_KEY' | |
# risk – «Общий риск», | |
# frequency – «Повторы», | |
# style – «Стилистика», | |
# keywords – «Запросы», | |
# formality – «Водность», | |
# readability – «Удобочитаемость». | |
api_type = 'risk' # Например, 'risk' или 'style' | |
# Укажите текст или URL, но не оба одновременно | |
text = File.read('text.txt').gsub("\n", "<br />") # Например, 'text.txt' | |
url = nil # Например, "https://somesite.ru/nazvanie-razdela/stranica" | |
tbclass = '.content' # CSS-селектор для URL | |
more = 1 # Установите 1 для детализированного ответа | |
check_text(api_key, api_type, text: text, url: url, tbclass: tbclass, more: more) | |
# Использование% | |
# 1. создать файл text.txt с проверяемым текстом | |
# 2. запустить комманду `ruby turgenev.rb` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Результат запроса
Ссылка: https://turgenev.ashmanov.com/?t=xxxx