Yaron Koresh commited on
Commit
af75145
·
verified ·
1 Parent(s): 7bd97cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -47,16 +47,17 @@ def translate(text,lang):
47
  'User-Agent': random.choice(user_agents)
48
  }
49
  )
50
- print(resp)
51
  content = resp.content
52
  html = fromstring(content)
53
  rslt = html.xpath('//pre[@aria-label="Translated text"]/span')
 
54
  translated = text
55
  try:
56
  t = rslt[0].text.strip()
57
  translated = t
58
  except:
59
- print(f'"{text}" is already in {lang}!')
 
60
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
61
  print(ret)
62
  return ret
 
47
  'User-Agent': random.choice(user_agents)
48
  }
49
  )
 
50
  content = resp.content
51
  html = fromstring(content)
52
  rslt = html.xpath('//pre[@aria-label="Translated text"]/span')
53
+ print(rslt)
54
  translated = text
55
  try:
56
  t = rslt[0].text.strip()
57
  translated = t
58
  except:
59
+ if( len(rslt)>=1 ):
60
+ print(f'"{text}" is already in {lang}!')
61
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
62
  print(ret)
63
  return ret