I have been using the translate package from https://pypi.org/project/translate/ to do some text translations. The provider used is microsoft.
When used its unable to translate some simple text which was possible using google trans.
from translate import Translator
translate = Translator(provider='microsoft', to_lang='en', secret_access_key='xxxx')
translate.translate('作成者')
Out[20]: '作成者'
Can someone help me with the issue?
Expected result :
google_translator.translate('作成者',dest='en').text
Out[22]: 'Author'
I checked the repository of the package you are using and it looks like it has been long since it was last updated.
It uses the Base URL of Translator Text API v2.0 which was deprecated at the beginning of 2018:
https://api.microsofttranslator.com/V2/Http.svc/Translate
Which is different from the one that the new Translator Text API v3.0 uses:
api.cognitive.microsofttranslator.com
In order to get going, I suggest you check the Python, REST quickstart in the documentation that shows you how to translate a text string using Python and the Translator Text REST API, or if you'd like you can check all the code at once!
Related
I am new to python and want to convert speech to text using python libraries.But not using APIs.Basically,I want my code to run without internet too.Which library I should use?I have learned SpeechRecognition is the simplest one but I see in every use case it makes use of an API.Please suggest how should I proceed.
You can try using pyttsx3 module. It stands for Python Text To Speech version 3.
you can check out my GitHub repo to learn about the use of speech recognition and pyttsx3.
https://github.com/shuvampaul2005/J.A.R.V.I.S
Hello friends and colleagues...
A quick question How do Iconvert JSON file into PO?
I had a PO file with relevant translations, then I converted it to JSON on some website after that wrote a little script in NodeJS to translate keys via Google translate API and now I just want to convert this translated JSON back to PO...
Is there any easy way? I don't seem to find any working npm packages or anything else...
Please Help,
Thanks
Online tools like https://localise.biz/free/converter/po-to-json can help.
To translate using command line there's an open source repo on Git- https://github.com/2gis/i18n-json-po
I recently learned that Companies House has API that allows access to companies filling history and I want to get data from the API and load it in pandas dataframe.
I have set up API account but I am having difficulties with the python wrapper companies-house 0.1.2 https://pypi.org/project/companies-house/
from companies_house.api import CompaniesHouseAPI
ch = CompaniesHouseAPI('my_api_key')
This works, but when I try to get the data with get_company or get_company_filing_history I seem to pass incorrect parameters. I tried passing CompaniesHouseAPI.get_company('02627406') but get KeyError: 'company_number'. Quite puzzled as there is no example provided in the documentation. Please help me figure out what should I pass as a parameter/parameters in both functions.
# what errors
CompaniesHouseAPI.get_company('02627406')
I am not a python expert but want to learn by doing interesting projects. Please help. If you know how to get financial history from Companies House API using another python wrapper your solution is also welcome.
I recently wrote a blog post describing how to make your own wrapper and then use that to create an application that loads the data into a pandas dataframe as you described. You can find it here.
By creating your own wrapper class, you avoid the limitations of whichever library you have chosen. You may also learn a lot about calling an API from python and working with the response.
Here is a code example that does not need a Companies House-specific library.
import requests
import json
url = "https://api.companieshouse.gov.uk/search/companies?q={}"
query = "tesco"
api_key = "vLmk-4YxYS-QH8nMi8767zJSlcPlo3MKn41-d" #Fake key - insert your key here
response = requests.get(url.format(query),auth=(api_key,''))
json_search_result = response.text
search_result = json.JSONDecoder().decode(json_search_result)
for company in search_result['items']:
print(company['title'])
Running this should give you the top 20 matches for the keyword "tesco" from the Companies House search function. Check out the blog post to see how you could adapt this to perform any function from the API.
I'm trying to make simple Python 3 program to read weather information from XML web source, convert it into Python-readable object (maybe dictionary) and process it (for example visualize multiple observations into graph).
Source of data is national weather service's (direct translation) xml file at link provided in code.
What's different from typical XML parsing related question in Stack Overflow is that there are repetitive tags without in-tag identificator (<station> tags in my example) and some with (1st line, <observations timestamp="14568.....">). Also I would like to try parse it straight from website, not local file. Of course, I could create local temporary file too.
What I have so far, is simply loading script, that gives string containing xml code for both forecast and latest weather observations.
from urllib.request import urlopen
#Read 4-day forecast
forecast= urlopen("http://www.ilmateenistus.ee/ilma_andmed/xml/forecast.php").read().decode("iso-8859-1")
#Get current weather
observ=urlopen("http://www.ilmateenistus.ee/ilma_andmed/xml/observations.php").read().decode("iso-8859-1")
Shortly, I'm looking for as universal as possible way to parse XML to Python-readable object (such as dictionary/JSON or list) while preserving all of the information in XML-file.
P.S I prefer standard Python 3 module such as xml, which I didn't understand.
Try xmltodict package for simple conversion of XML structure to Python dict: https://github.com/martinblech/xmltodict
I have a public etherpad containing an yaml-file. Using php I would like read this yaml and convert it to a json-string.
There are some great libraries for converting yaml to json. for example:
https://github.com/mustangostang/spyc/
What i'm looking for is an url that will return the contents of a pad as pure text.
You want the text export then. You can easily get the contents of a pad exported as raw text, using the following url:
//<yourdomain>.com/p/<yourpad>/export/txt