Look only for French dictionary entries

This commit is contained in:
Benjamin Loison 2024-04-01 01:22:10 +02:00
parent a39d22ab72
commit c90beee5fc
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

21
main.py
View File

@ -13,21 +13,24 @@ MAXIMUM_SUGGESTIONS = 4
entries = set() entries = set()
def treatSuffixes(prefix): def treatSuffixes(prefix):
print(prefix) #print(prefix)
for char in charset: for char in charset:
base = prefix + char base = prefix + char
print(base)
params['qe'] = base params['qe'] = base
text = requests.get(url, params = params).text text = requests.get(url, params = params).text
tree = html.fromstring(text) tree = html.fromstring(text)
items = tree.xpath('//div[@class="main_item"]') rows = tree.xpath('//div[@class="main_row"]')
itemsLen = len(items) rowsLen = len(rows)
assert itemsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} items!' assert rowsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} rows!'
for item in items: for row in rows:
item = row.xpath('div[@class="main_item"]')[0]
entry = item.text_content() entry = item.text_content()
if not entry in entries: wordType = row.xpath('div[@class="main_wordtype"]')
print(len(entries), entry) if wordType != [] and item.attrib['lc'] == 'FR' and not entry in entries:
entries.add(entry) print(len(entries), entry, wordType[0].text_content())
if itemsLen == MAXIMUM_SUGGESTIONS: entries.add(entry)
if rowsLen == MAXIMUM_SUGGESTIONS:
treatSuffixes(base) treatSuffixes(base)
treatSuffixes('') treatSuffixes('')