79304258

Date: 2024-12-23 21:22:18
Score: 0.5
Natty:
Report link

Thanks to esqew for informing me that PyDictionary probably no longer works. I found another library that does work; here is the new code:

# Import Libraries
from tkinter import *
from gtts import gTTS
from freedictionaryapi.clients.sync_client import DictionaryApiClient
import random

# Create Functions
def chooserandom(list: list):
    return list[random.randrange(0, len(list))]
def getdefinitions(word: str):
    with DictionaryApiClient() as client:
        parser = client.fetch_parser(word)
    return parser.meanings

# Create Variables
words: list[str] = "".join(list(open("word-lists\\mainlist.txt", "r"))).split("\n")

# Main Loop
word: str = chooserandom(words)
definition = getdefinitions(word)
print(word) # amber
print(definition) # [Meaning(part_of_speech='noun', definitions=[Definition(definition='Ambergris, the waxy product of the sperm whale.', example=None, synonyms=[]), Definition(definition='A hard, generally yellow to brown translucent fossil resin, used for jewellery. One variety, blue amber, appears blue rather than yellow under direct sunlight.', example=None, synonyms=[]), Definition(definition='A yellow-orange colour.', example=None, synonyms=[]), Definition(definition='The intermediate light in a set of three traffic lights, which when illuminated indicates that drivers should stop short of the intersection if it is safe to do so.', example=None, synonyms=[]), Definition(definition='The stop codon (nucleotide triplet) "UAG", or a mutant which has this stop codon at a premature place in its DNA sequence.', example='an amber codon, an amber mutation, an amber suppressor', synonyms=[])]), Meaning(part_of_speech='verb', definitions=[Definition(definition='To perfume or flavour with ambergris.', example='ambered wine, an ambered room', synonyms=[]), Definition(definition='To preserve in amber.', example='an ambered fly', synonyms=[]), Definition(definition='To cause to take on the yellow colour of amber.', example=None, synonyms=[]), Definition(definition='To take on the yellow colour of amber.', example=None, synonyms=[])]), Meaning(part_of_speech='adjective', definitions=[Definition(definition='Of a brownish yellow colour, like that of most amber.', example=None, synonyms=[])])]

Just make sure you have run both commands (Windows):

pip install python-freeDictionaryAPI
pip install httpx

Thanks for the help!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: caiamari