Skip to content

Commit

Permalink
Merge PR #210 from WayneLambert/countdown-letters-remove-api
Browse files Browse the repository at this point in the history
Remove Oxford Dictionaries API Functionality
  • Loading branch information
WayneLambert authored Mar 5, 2024
2 parents 1f21275 + 6712d70 commit 6fb5667
Show file tree
Hide file tree
Showing 19 changed files with 6 additions and 2,579 deletions.
43 changes: 2 additions & 41 deletions apps/countdown_letters/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
"""

import os

from collections import Counter
from random import choices, random
from typing import Dict, List, Set

import requests

from aa_project.settings.base import APPS_DIR
from apps.countdown_letters import validations
from apps.countdown_letters.oxford_api import API


class GameSetup:
Expand Down Expand Up @@ -141,9 +136,8 @@ def get_longest_possible_word(shortlisted_words: List) -> str:
indexed position
"""
for item in shortlisted_words:
if validations.is_in_oxford_api(item[0]):
longest_possible_word = item[0]
return longest_possible_word.upper()
longest_possible_word = item[0]
return longest_possible_word.upper()
return None


Expand All @@ -152,39 +146,6 @@ def get_game_score(word_len: int) -> int:
return word_len * 2 if word_len == 9 else word_len


def get_lemmas_response_json(word: str) -> Dict:
"""
Returns lemmas data component of given `word` from Oxford Online API
The `lemmas` endpoint is used to determine presence in the dictionary.
"""
lemmas_url = f"{API.LEMMAS_URL}{word.lower()}"
lemmas_response = requests.get(lemmas_url, headers=API.headers)
return lemmas_response.json()


def lookup_definition_data(word: str) -> Dict:
"""
Retrieve dictionary definition of winning word using 'Oxford
Dictionaries API'.
"""
response = requests.get(url=API.WORDS_URL, params={"q": word}, headers=API.headers)
if response.status_code == 200:
try:
json = response.json()
idx = 0 if json["results"][0]["type"] == "headword" else 1
d = json["results"][idx]["lexicalEntries"][0]["entries"][0]["senses"][0]
definition = d["definitions"][0].capitalize()
word_class = json["results"][0]["lexicalEntries"][idx]["lexicalCategory"]["text"]
except KeyError:
definition = f"The definition for '{word}' cannot be found in the Oxford Dictionaries API."
word_class = "N/A"

return {
"definition": definition,
"word_class": word_class,
}


def get_result(player_word: str, comp_word: str) -> str:
"""Returns the winning player for the game"""
if len(player_word) > len(comp_word):
Expand Down
24 changes: 0 additions & 24 deletions apps/countdown_letters/oxford_api.py

This file was deleted.

21 changes: 0 additions & 21 deletions apps/countdown_letters/templates/countdown_letters/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,6 @@ <h6 class="font-weight-bold mb-0 lead mb-4">Player Answers</h6>
</blockquote>
</div>

<!--- Word Definition -->
<div class="client-quote d-flex flex-column results-card mb-1 mt-3">
<blockquote class="quote-content text-left">
<h6 class="font-weight-bold mb-0 lead mb-4">Word Definition</h6>
<table>
<tr>
<h6 class="text-uppercase">
<strong>{{ winning_word|lower|capfirst }}</strong>
</h6>
</tr>
<tr>
<div class="inner theme-bg-light">
<p class="text-small text-muted">{{ definition_data.word_class }}</p>
<p class="word-definition">{{ definition_data.definition }}</p>
<em class="small">(British - English)</em>
</div>
</tr>
</table>
</blockquote>
</div>

<!--- Scores Message -->
<div class="client-quote d-flex flex-column results-card mt-3">
<blockquote class="quote-content text-left">
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6fb5667

Please sign in to comment.