Giter Site home page Giter Site logo

Comments (8)

sirEgghead avatar sirEgghead commented on July 4, 2024

This is a single test request that I made just now. There is no other activity from my app today, besides a few tests from myself. The application worked fine until it decided to start returning status code 429, without any code changes.

Today, after seeing your note about the batch update, I did quickly update the code to send batches, because each translation request that my app creates actually requests for multiple languages. So I am now using the batch request, which should take my 20 requests per day down to maybe 4 per day.

image

from google-translate-api.

AidanWelch avatar AidanWelch commented on July 4, 2024

Issue 12 wasn't finished being addressed before it was closed. My app wouldn't hit the rate limit as it sends fewer than 20 requests per day.

I closed it because there was no response after several days of it attempting to be addressed.

from google-translate-api.

AidanWelch avatar AidanWelch commented on July 4, 2024

This is a single test request that I made just now. There is no other activity from my app today, besides a few tests from myself. The application worked fine until it decided to start returning status code 429, without any code changes.

Can you share your code? I'm not able to reproduce the issue.

from google-translate-api.

sirEgghead avatar sirEgghead commented on July 4, 2024
const key = require('./api.json')
const { Telegraf } = require('telegraf')
// const fs = require('fs')
const bot = new Telegraf(key.key)
const { Worker } = require('worker_threads')
const translate = require('google-translate-api-x')

bot.start((ctx) => ctx.reply('SSQ Translation Bot'))
bot.on('message', (ctx) => printTranslations(ctx.message.text, ctx))
bot.launch()

process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))


async function printTranslations(text, ctx) {
  let res = await translateFive(text)
  if (res) {
    const languages = {
      'en': 'English',
      'es': 'Español',
      'de': 'Deutsch',
      'pl': 'Polski',
      'ru': 'Русский',
      'cn': '中文',
    }
    let translated = ''
    Object.keys(languages).forEach(key => {
      translated += `*${languages[key]}:* ${res[key]}`
      translated += '\n\n'
    })
    // ctx.reply(translated, {reply_to_message_id: ctx.message.message_id})
    ctx.replyWithMarkdownV2(translated, {reply_to_message_id: ctx.message.message_id})
  }
}

async function translateFive(text) {
  const textArray = [
    {text: text, to: 'en'},
    {text: text, to: 'es'},
    {text: text, to: 'de'},
    {text: text, to: 'ru'},
    {text: text, to: 'pl'},
    {text: text, to: 'zn-CN'},
  ];

  try {
    const translated = await translate(textArray);
    return {
      'en': translated[0].text,
      'es': translated[1].text,
      'de': translated[2].text,
      'ru': translated[3].text,
      'pl': translated[4].text,
      'cn': translated[5].text,
    }
  } catch (e) {
    console.log(e.message);
    return null;
  }
}

console.log('Bot running.')

from google-translate-api.

sirEgghead avatar sirEgghead commented on July 4, 2024

And this was the original one, as of this morning, before switching to the new batch feature.

const key = require('./api.json')
const { Telegraf } = require('telegraf')
const bot = new Telegraf(key.key)
const { Worker } = require('worker_threads')
const translate = require('google-translate-api-x')

bot.start((ctx) => ctx.reply('SSQ Translation Bot'))
bot.on('message', (ctx) => printTranslations(ctx.message.text, ctx))
bot.launch()

process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))


async function printTranslations(text, ctx) {
  let res = await translateFive(text)
  const languages = {
    'en': 'English',
    'es': 'Español',
    'de': 'Deutsch',
    'pl': 'Polski',
    'ru': 'Русский',
    'cn': '中文',
  }
  let translated = ''
  Object.keys(languages).forEach(key => {
    translated += `*${languages[key]}:* ${res[key]}`
    translated += '\n\n'
  })
  ctx.replyWithMarkdownV2(translated, {reply_to_message_id: ctx.message.message_id})
}

async function translateFive(text) {
  let en = await translate(text, {to: 'en'})
  let es = await translate(text, {to: 'es'})
  let de = await translate(text, {to: 'de'})
  let ru = await translate(text, {to: 'ru'})
  let pl = await translate(text, {to: 'pl'})
  let cn = await translate(text, {to: 'zh-CN'})
  return {
    'en': en.text,
    'es': es.text,
    'de': de.text,
    'ru': ru.text,
    'pl': pl.text,
    'cn': cn.text,
  }
}

console.log('Bot running.')

from google-translate-api.

sirEgghead avatar sirEgghead commented on July 4, 2024

I migrated the server to a new IP address and I seem to have full operation at this point. Maybe the rate limit being hit was tied to that IP address somehow. Possibly from where I was sending 5 requests per translation. I'm kind of grasping at straws here, but at least for the time being, it seems to be working with the new IP address and using batch requests. I'll update you if anything changes.

from google-translate-api.

AidanWelch avatar AidanWelch commented on July 4, 2024

I'm kind of grasping at straws here, but at least for the time being, it seems to be working with the new IP address and using batch requests. I'll update you if anything changes.

Okay that's good, my best guess is that Google detected in some way your behavior as malicious and rate limited you, but I can't reproduce it.

from google-translate-api.

AidanWelch avatar AidanWelch commented on July 4, 2024

Closed as stale

from google-translate-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.