# wrpy
This is a Python package to obtain translations from [wordreference.com](https://wordreference.com) transforming returned data into normalized and structured datatypes.
## Installation
```console
$ pip install wrpy
```
## Usage
You can get the **available dictionaries** using the following function:
```pycon
>>> from wrpy import get_available_dicts
>>> get_available_dicts()
{'enes': {'from': 'English', 'to': 'Spanish'},
'esen': {'from': 'Spanish', 'to': 'English'},
'esfr': {'from': 'Spanish', 'to': 'French'},
'espt': {'from': 'Spanish', 'to': 'Portuguese'},
'esit': {'from': 'Spanish', 'to': 'Italian'},
'esde': {'from': 'Spanish', 'to': 'German'},
'esca': {'from': 'Spanish', 'to': 'Catalan'},
'enfr': {'from': 'English', 'to': 'French'},
'fren': {'from': 'French', 'to': 'English'},
'fres': {'from': 'French', 'to': 'Spanish'},
'enit': {'from': 'English', 'to': 'Italian'},
'iten': {'from': 'Italian', 'to': 'English'},
'ites': {'from': 'Italian', 'to': 'Spanish'},
'ende': {'from': 'English', 'to': 'German'},
'deen': {'from': 'German', 'to': 'English'},
'dees': {'from': 'German', 'to': 'Spanish'},
'ennl': {'from': 'English', 'to': 'Dutch'},
'nlen': {'from': 'Dutch', 'to': 'English'},
'ensv': {'from': 'English', 'to': 'Swedish'},
'sven': {'from': 'Swedish', 'to': 'English'},
'enru': {'from': 'English', 'to': 'Russian'},
'ruen': {'from': 'Russian', 'to': 'English'},
'enpt': {'from': 'English', 'to': 'Portuguese'},
'pten': {'from': 'Portuguese', 'to': 'English'},
'ptes': {'from': 'Portuguese', 'to': 'Spanish'},
'enpl': {'from': 'English', 'to': 'Polish'},
'plen': {'from': 'Polish', 'to': 'English'},
'enro': {'from': 'English', 'to': 'Romanian'},
'roen': {'from': 'Romanian', 'to': 'English'},
'encz': {'from': 'English', 'to': 'Czech'},
'czen': {'from': 'Czech', 'to': 'English'},
'engr': {'from': 'English', 'to': 'Greek'},
'gren': {'from': 'Greek', 'to': 'English'},
'entr': {'from': 'English', 'to': 'Turkish'},
'tren': {'from': 'Turkish', 'to': 'English'},
'enzh': {'from': 'English', 'to': 'Chinese'},
'zhen': {'from': 'Chinese', 'to': 'English'},
'enja': {'from': 'English', 'to': 'Japanese'},
'jaen': {'from': 'Japanese', 'to': 'English'},
'enko': {'from': 'English', 'to': 'Korean'},
'koen': {'from': 'Korean', 'to': 'English'},
'enar': {'from': 'English', 'to': 'Arabic'},
'aren': {'from': 'Arabic', 'to': 'English'}}
```
> ⚠️ Next dicts are not working properly since their response is not structured in the same way as the others:
>
> - Spanish to Catalan
> - Russian to English
In order to **translate a word**, you can follow this workflow:
```pycon
>>> from wrpy import WordReference
>>> wr = WordReference('es', 'en') # same as WordReference('esen')
>>> wr.translate('teclado')
{'word': 'teclado',
'from_lang': 'Spanish',
'to_lang': 'English',
'url': 'https://www.wordreference.com/esen/teclado',
'translations': [{'title': 'Principal Translations',
'entries': [{'from_word': {'source': 'teclado',
'grammar': 'nombre masculino'},
'to_word': [{'meaning': 'keyboard', 'notes': None, 'grammar': 'noun'},
{'meaning': 'keypad, touchpad', 'notes': None, 'grammar': 'noun'}],
'context': 'tablero con teclas',
'from_example': 'No me funciona bien el teclado del portátil.',
'to_example': ["The laptop keyboard isn't working well."]}]},
{'title': 'Additional Translations',
'entries': [{'from_word': {'source': 'teclado',
'grammar': 'nombre masculino'},
'to_word': [{'meaning': 'keyboard', 'notes': 'music', 'grammar': 'noun'}],
'context': 'piano electrónico',
'from_example': 'Aprendí a tocar el teclado de adolescente.',
'to_example': ['I learned to play the keyboard when I was a teenager.']},
{'from_word': {'source': 'teclado', 'grammar': 'nombre masculino'},
'to_word': [{'meaning': 'keyboard', 'notes': 'piano', 'grammar': 'noun'},
{'meaning': 'keys', 'notes': None, 'grammar': 'plural noun'}],
'context': 'teclas del piano',
'from_example': 'Este señor viene a afinar el teclado del piano de cola.',
'to_example': ["This man has come to fine tune the grand piano's keyboard"]}]}]}
```
## Response
Response fields from calling `translate()` method:
```python
response {}
├ word
├ from_lang
├ to_lang
├ url # hitted url
└ translations []
├ title # title of each section
└ entries []
├ context
├ from_word {}
│ ├ source # source word
│ └ grammar # grammar tips about source word
├ to_word []
│ ├ meaning
│ ├ notes # clarification about meaning
│ └ grammar # grammar tips about meaning
├ from_example
└ to_example []
```
Response is composed by sections (inside the `translations` list) as they appear in [wordreference.com](https://wordreference.com)
Number of entries is limited to 100 results.
## Disclaimer
The workflow of this package is based on scraping of [wordreference.com](https://wordreference.com). Thus, future changes on the structure of html response may affect the results.
Raw data
{
"_id": null,
"home_page": "",
"name": "wrpy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "translation tools wordreference automation productivity",
"author": "Sergio Delgado Quintero",
"author_email": "sdelquin@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/41/61/31b1223ca205db7f9d27a5211ee759382b4df01bbd8ade54d456ee51537c/wrpy-0.1.1.tar.gz",
"platform": "any",
"description": "# wrpy\n\nThis is a Python package to obtain translations from [wordreference.com](https://wordreference.com) transforming returned data into normalized and structured datatypes.\n\n## Installation\n\n```console\n$ pip install wrpy\n```\n\n## Usage\n\nYou can get the **available dictionaries** using the following function:\n\n```pycon\n>>> from wrpy import get_available_dicts\n\n>>> get_available_dicts()\n{'enes': {'from': 'English', 'to': 'Spanish'},\n 'esen': {'from': 'Spanish', 'to': 'English'},\n 'esfr': {'from': 'Spanish', 'to': 'French'},\n 'espt': {'from': 'Spanish', 'to': 'Portuguese'},\n 'esit': {'from': 'Spanish', 'to': 'Italian'},\n 'esde': {'from': 'Spanish', 'to': 'German'},\n 'esca': {'from': 'Spanish', 'to': 'Catalan'},\n 'enfr': {'from': 'English', 'to': 'French'},\n 'fren': {'from': 'French', 'to': 'English'},\n 'fres': {'from': 'French', 'to': 'Spanish'},\n 'enit': {'from': 'English', 'to': 'Italian'},\n 'iten': {'from': 'Italian', 'to': 'English'},\n 'ites': {'from': 'Italian', 'to': 'Spanish'},\n 'ende': {'from': 'English', 'to': 'German'},\n 'deen': {'from': 'German', 'to': 'English'},\n 'dees': {'from': 'German', 'to': 'Spanish'},\n 'ennl': {'from': 'English', 'to': 'Dutch'},\n 'nlen': {'from': 'Dutch', 'to': 'English'},\n 'ensv': {'from': 'English', 'to': 'Swedish'},\n 'sven': {'from': 'Swedish', 'to': 'English'},\n 'enru': {'from': 'English', 'to': 'Russian'},\n 'ruen': {'from': 'Russian', 'to': 'English'},\n 'enpt': {'from': 'English', 'to': 'Portuguese'},\n 'pten': {'from': 'Portuguese', 'to': 'English'},\n 'ptes': {'from': 'Portuguese', 'to': 'Spanish'},\n 'enpl': {'from': 'English', 'to': 'Polish'},\n 'plen': {'from': 'Polish', 'to': 'English'},\n 'enro': {'from': 'English', 'to': 'Romanian'},\n 'roen': {'from': 'Romanian', 'to': 'English'},\n 'encz': {'from': 'English', 'to': 'Czech'},\n 'czen': {'from': 'Czech', 'to': 'English'},\n 'engr': {'from': 'English', 'to': 'Greek'},\n 'gren': {'from': 'Greek', 'to': 'English'},\n 'entr': {'from': 'English', 'to': 'Turkish'},\n 'tren': {'from': 'Turkish', 'to': 'English'},\n 'enzh': {'from': 'English', 'to': 'Chinese'},\n 'zhen': {'from': 'Chinese', 'to': 'English'},\n 'enja': {'from': 'English', 'to': 'Japanese'},\n 'jaen': {'from': 'Japanese', 'to': 'English'},\n 'enko': {'from': 'English', 'to': 'Korean'},\n 'koen': {'from': 'Korean', 'to': 'English'},\n 'enar': {'from': 'English', 'to': 'Arabic'},\n 'aren': {'from': 'Arabic', 'to': 'English'}}\n```\n\n> \u26a0\ufe0f Next dicts are not working properly since their response is not structured in the same way as the others:\n>\n> - Spanish to Catalan\n> - Russian to English\n\nIn order to **translate a word**, you can follow this workflow:\n\n```pycon\n>>> from wrpy import WordReference\n\n>>> wr = WordReference('es', 'en') # same as WordReference('esen')\n\n>>> wr.translate('teclado')\n{'word': 'teclado',\n 'from_lang': 'Spanish',\n 'to_lang': 'English',\n 'url': 'https://www.wordreference.com/esen/teclado',\n 'translations': [{'title': 'Principal Translations',\n 'entries': [{'from_word': {'source': 'teclado',\n 'grammar': 'nombre masculino'},\n 'to_word': [{'meaning': 'keyboard', 'notes': None, 'grammar': 'noun'},\n {'meaning': 'keypad, touchpad', 'notes': None, 'grammar': 'noun'}],\n 'context': 'tablero con teclas',\n 'from_example': 'No me funciona bien el teclado del port\u00e1til.',\n 'to_example': [\"The laptop keyboard isn't working well.\"]}]},\n {'title': 'Additional Translations',\n 'entries': [{'from_word': {'source': 'teclado',\n 'grammar': 'nombre masculino'},\n 'to_word': [{'meaning': 'keyboard', 'notes': 'music', 'grammar': 'noun'}],\n 'context': 'piano electr\u00f3nico',\n 'from_example': 'Aprend\u00ed a tocar el teclado de adolescente.',\n 'to_example': ['I learned to play the keyboard when I was a teenager.']},\n {'from_word': {'source': 'teclado', 'grammar': 'nombre masculino'},\n 'to_word': [{'meaning': 'keyboard', 'notes': 'piano', 'grammar': 'noun'},\n {'meaning': 'keys', 'notes': None, 'grammar': 'plural noun'}],\n 'context': 'teclas del piano',\n 'from_example': 'Este se\u00f1or viene a afinar el teclado del piano de cola.',\n 'to_example': [\"This man has come to fine tune the grand piano's keyboard\"]}]}]}\n```\n\n## Response\n\nResponse fields from calling `translate()` method:\n\n```python\nresponse {}\n \u251c word\n \u251c from_lang\n \u251c to_lang\n \u251c url # hitted url\n \u2514 translations []\n \u251c title # title of each section\n \u2514 entries []\n \u251c context\n \u251c from_word {}\n \u2502 \u251c source # source word\n \u2502 \u2514 grammar # grammar tips about source word\n \u251c to_word []\n \u2502 \u251c meaning\n \u2502 \u251c notes # clarification about meaning\n \u2502 \u2514 grammar # grammar tips about meaning\n \u251c from_example\n \u2514 to_example []\n\n```\n\nResponse is composed by sections (inside the `translations` list) as they appear in [wordreference.com](https://wordreference.com)\n\nNumber of entries is limited to 100 results.\n\n## Disclaimer\n\nThe workflow of this package is based on scraping of [wordreference.com](https://wordreference.com). Thus, future changes on the structure of html response may affect the results.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Get translations from WordReference.",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/sdelquin/wrpy/blob/main/README.md",
"Download": "https://github.com/sdelquin/wrpy",
"Issue Tracker": "https://github.com/sdelquin/wrpy/issues",
"Source Code": "https://github.com/sdelquin/wrpy"
},
"split_keywords": [
"translation",
"tools",
"wordreference",
"automation",
"productivity"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "16a6783c406ab42f576a1a79246470202f2f4229342122ea69393528579c8adb",
"md5": "0ef74e48032a56b8b4d940b8db080a46",
"sha256": "16fafeafccd3e88dcba20785f98110582f11a03975a0bf5fc7fbc8bf916d63a0"
},
"downloads": -1,
"filename": "wrpy-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0ef74e48032a56b8b4d940b8db080a46",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 6065,
"upload_time": "2024-01-17T17:26:59",
"upload_time_iso_8601": "2024-01-17T17:26:59.831526Z",
"url": "https://files.pythonhosted.org/packages/16/a6/783c406ab42f576a1a79246470202f2f4229342122ea69393528579c8adb/wrpy-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "416131b1223ca205db7f9d27a5211ee759382b4df01bbd8ade54d456ee51537c",
"md5": "71f358cd739b0c34ca62dd48ae0073b5",
"sha256": "1ed3a6ef3d2b4c23bbcac848e6a71c90bbf6d3f0af6a3377cb7838a06dda4432"
},
"downloads": -1,
"filename": "wrpy-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "71f358cd739b0c34ca62dd48ae0073b5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8577,
"upload_time": "2024-01-17T17:27:02",
"upload_time_iso_8601": "2024-01-17T17:27:02.360038Z",
"url": "https://files.pythonhosted.org/packages/41/61/31b1223ca205db7f9d27a5211ee759382b4df01bbd8ade54d456ee51537c/wrpy-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-17 17:27:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sdelquin",
"github_project": "wrpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": []
},
{
"name": "beautifulsoup4",
"specs": []
},
{
"name": "user_agent",
"specs": [
[
"==",
"0.1.10"
]
]
}
],
"lcname": "wrpy"
}