├── Procfile ├── README.md ├── templates ├── wordnotfound.html ├── word.html └── base.html ├── requirements.txt ├── LICENSE └── app.py /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimplyVocab: A minimalist English dictionary 2 | 3 | Go to https://simplyvocab.onrender.com to see it in action. 4 | -------------------------------------------------------------------------------- /templates/wordnotfound.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 |

**WORD NOT FOUND**

4 |

Sorry, but the API didn't return any definitions. Either the word is misspelled or 5 | the word doesn't exist in the dictionary.

6 | {% endblock %} -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2020.12.5 2 | chardet==4.0.0 3 | click==7.1.2 4 | decorator==5.0.5 5 | eng-to-ipa==0.0.2 6 | Flask==1.1.2 7 | gunicorn==20.1.0 8 | idna==2.10 9 | itsdangerous==1.1.0 10 | Jinja2==2.11.3 11 | jsonpath-ng==1.5.2 12 | MarkupSafe==1.1.1 13 | ply==3.11 14 | requests==2.25.1 15 | six==1.15.0 16 | urllib3==1.26.4 17 | Werkzeug==1.0.1 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 django0212 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /templates/word.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 | 4 |
5 |

{{ name }}

6 |

{{ pronun }}

7 |
8 | {% if aun == None %} 9 | 10 |
11 |
12 | 14 |
15 |
16 | {% endif %} 17 | {% for p, d, e, s in ding %} 18 | {% if p != None %} 19 |
20 |
{{ p }}
21 | {% endif %} 22 |
23 |
{{ d }}
24 | {% if e != "_" %} 25 |

{{ e }}

26 | {% endif %} 27 |
28 |
29 | {% if s != "_" %} 30 |
31 |
32 |

33 | 38 |

39 |
41 |
42 | {% for x in s %} 43 | {{ x }} 44 | {% endfor %} 45 |
46 |
47 |
48 |
49 |
50 | {% endif %} 51 | {% endfor %} 52 | {% endblock %} 53 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import requests 3 | import jsonpath_ng 4 | import json 5 | 6 | app = Flask(__name__) 7 | 8 | 9 | @app.route('/') 10 | def index(): 11 | return render_template("base.html") 12 | 13 | 14 | @app.route('/', methods=['POST']) 15 | def my_form_post(): 16 | text = request.form['text'] 17 | if text != "": 18 | return defn(text) 19 | else: 20 | return render_template("base.html") 21 | 22 | 23 | def defn(name): 24 | url = "https://api.dictionaryapi.dev/api/v2/entries/en_US/{}".format(name) 25 | 26 | response = requests.get(url) 27 | 28 | entries = response.json() 29 | 30 | try: 31 | query_word = jsonpath_ng.parse('[0].word[*]') 32 | for match in query_word.find(entries): 33 | word = (json.dumps(match.value)).strip('"') 34 | 35 | query_pronun = jsonpath_ng.parse('[0].phonetics[*].text[*]') 36 | for match in query_pronun.find(entries): 37 | pronun = json.loads(json.dumps(match.value)) 38 | query_audio = jsonpath_ng.parse('[0].phonetics[*].audio[*]') 39 | for match in query_audio.find(entries): 40 | audio_link = (json.dumps(match.value)).strip('"') 41 | 42 | # part of speech 43 | pos = [] 44 | # definitions 45 | defs = [] 46 | # examples 47 | expl = [] 48 | # synonyms 49 | syns = [] 50 | 51 | for entry in entries: 52 | for meaning in entry["meanings"]: 53 | for definition in meaning["definitions"]: 54 | pos.append(meaning["partOfSpeech"]) 55 | defs.append(definition["definition"]) 56 | if "example" in definition: 57 | expl.append(definition["example"]) 58 | else: 59 | expl.append("_") 60 | if "synonyms" in definition: 61 | syns.append(definition["synonyms"]) 62 | else: 63 | syns.append("_") 64 | ding = zip(pos, defs, expl, syns) 65 | # this is to show the play audio button only when a word is present 66 | aun = None 67 | except KeyError: 68 | # render wordnotfound.html if api doesn't return defs 69 | return render_template("wordnotfound.html"), 404 70 | return render_template("word.html", name=word, pronun=pronun, audio=audio_link, ding=ding, aun=aun) 71 | -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 29 | 30 | SimplyVocab 31 | 32 | 56 | 57 | 58 |
59 |

SimplyVocab

60 |
61 |
62 |
63 | 65 | 66 | 67 |   68 |
69 | 70 |
71 |
72 |
73 |
74 | {% block content %} 75 |

Note: this website's word suggestion functionality doesn't work properly with Firefox and some mobile browsers.

76 | {% endblock %} 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | --------------------------------------------------------------------------------