Parsers

This module provides different parsers (children of Parser) to obtain the necessary data to fill Anki-Cards.

Each parser returns a dict, that can directly be used by the pt_word.Word.update_from_dict() method of the pt_word.Word class.

class acg.parsers.AsyncDicio[source]

Bases: acg.parsers.AsyncParser

Uses Dicio to obtain: explanations, synonyms, antonyms, examples, add_info_dict, conj_table_html.

parse_response(self, response: dict or list or str)[source]

Extract: explanations, synonyms, antonyms, examples, add_info_dict, conj_table_html.

request_params(self)[source]

Return request params.

class acg.parsers.AsyncGoogleImages[source]

Bases: acg.parsers.AsyncParser

Uses google_images_download to get img_urls.

class acg.parsers.AsyncLinguee[source]

Bases: acg.parsers.AsyncParser

Get translation, word_type, gender, audio from Linguee.

parse_response(self, response: dict or list or str)[source]

Extract: translation, word_type, gender, audio_url.

request_params(self)[source]

Return request params.

class acg.parsers.AsyncParser[source]

Base-Class for asynchronous parsers.

static format_str(some_str)[source]

Replace spaces and special characters.

parse_response(self, response: dict or list or str)[source]

Placeholder-function.

request(self, url=None, request_params=None)[source]

Make http-request using :package:`aiohttp`.

request_params(self)[source]

Return request-params.

result_dict(self, phrase)[source]

Return results synchronously.

url(self, url=None)[source]

Return url for request.

class acg.parsers.AsyncReverso[source]

Bases: acg.parsers.AsyncParser

Use Reverso to obtain: examples.

parse_response(self, response: dict or list or str)[source]

Parse response and return dict of the form {"examples":[ [ex_src_lang, ex_trg_lang],...]]}.

url(self, url=None)[source]

Set up attributes.

class acg.parsers.CookBook[source]

Save recipes for construction of Classes with default values.

cook(self, name, **kwargs)

Generate object from recipe.

default_kwargs in recipe can be overridden by kwargs.

get_recipe_names(self)

Return list of all registered recipes.

get_recipes(self)

Return recipes.

register(self, recipe_name, info=None, **kwargs)

Add recipe to recipes.

to_button_dict(self)

Return dict in a form as used in custom_widgets.CustomSpeedDial.button_dicts.

acg.parsers.DEFAULT_HEADERS[source]

Default headers for the Parser class.

exception acg.parsers.NoMatchError(site='')[source]

Bases: Exception

Error if no match can be found for the current search.

class acg.parsers.Parser[source]

Base class for parsers.

Main functionality is the result_dict function.

base_url = [source]

URL to make request to. Can contain every class attribute. E.g. https://some.url/{phrase}/dest={from_lang};src={to_lang}.html

format_url_with_attribs(self, url=None)[source]

Get format_url_with_attribs for http-request.

Returns:base_url formatted with all class attributes.
from_lang = [source]

Target language.

headers[source]

Headers for the request. Defaults to DEFAULT_HEADERS.

make_request(self, url=None)[source]

Use headers to make an http-request via get().

Parameters:url – If None, will be set to format_url_with_attribs(). (Default value = None)
Returns:Response object
parse_response(self, response: requests.Response)[source]

Parse requests.response and return dict with result.

phrase = [source]

The word or phrase to search the site for.

result_dict(self, phrase=None)[source]

Use make_request() and parse_request() to return dict with result.

setup(self)[source]

Stuff that needs to be executed before format_url_with_attribs() is called.

to_lang = [source]

Source Language.

class acg.parsers.RandTopicWikiParser[source]

Bases: acg.parsers.Parser

Get title, summary and a list of image-urls for given random topic.

make_request(self, url=None, tries=10, category=None)[source]

Call base method if url is set. Else obtain response from random wiki page.

Because we only use content-pages and not category-pages try specifies how often we draw a random page.

parse_response(self, response: requests.Response)[source]

Extract title, summary, image_urls and return in dict.

acg.parsers.get_random_wiki_topic(category)[source]

Return page-string for a random page in a category.

acg.parsers.linguee_did_you_mean(search_term)[source]

Extract suggested corrections if the original search is not successful.

acg.parsers.remove_whitespace(some_string)[source]

Replace each group of whitespaces by a simple space (or by a newline if at least one is in the match).