Yaron Koresh commited on
Commit
397731d
·
verified ·
1 Parent(s): 14525e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -54,8 +54,8 @@ def translate(text,lang):
54
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
- query_text = 'english%20translate%20'+text.replace(" ","%20")
58
- url = f'https://www.google.co.il/search?q={query_text}&qo={query_text}'
59
 
60
  print(url)
61
 
@@ -72,12 +72,12 @@ def translate(text,lang):
72
  translated = text
73
 
74
  try:
75
- src_lang = html.xpath('//*[@class="source-language"]')[0].text_content().strip()
76
- trgt_lang = html.xpath('//*[@class="target-language"]')[0].text_content().strip()
77
- src_text = html.xpath('//*[@id="tw-source-text"]/*')[0].text_content().strip()
78
- trgt_text = html.xpath('//*[@id="tw-target-text"]/*')[0].text_content().strip()
79
 
80
- if trgt_lang.lower() == lang.lower():
81
  translated = trgt_text
82
  except:
83
  raise Exception("Translation Error!")
 
54
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
+ query_text = f'what is the {lang} translation of {text}'
58
+ url = f'http://google.com/search?q={query_text}'
59
 
60
  print(url)
61
 
 
72
  translated = text
73
 
74
  try:
75
+ src_lang = html.xpath('//*[@class="source-language"]')[0].text_content().lower().strip()
76
+ trgt_lang = html.xpath('//*[@class="target-language"]')[0].text_content().lower().strip()
77
+ src_text = html.xpath('//*[@id="tw-source-text"]/*')[0].text_content().lower().strip()
78
+ trgt_text = html.xpath('//*[@id="tw-target-text"]/*')[0].text_content().lower().strip()
79
 
80
+ if trgt_lang == lang:
81
  translated = trgt_text
82
  except:
83
  raise Exception("Translation Error!")