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.AsyncParserUses Dicio to obtain: explanations, synonyms, antonyms, examples, add_info_dict, conj_table_html.
-
class
acg.parsers.AsyncGoogleImages[source]¶ Bases:
acg.parsers.AsyncParserUses google_images_download to get img_urls.
-
class
acg.parsers.AsyncLinguee[source]¶ Bases:
acg.parsers.AsyncParserGet translation, word_type, gender, audio from Linguee.
-
class
acg.parsers.AsyncParser[source]¶ Base-Class for asynchronous parsers.
-
request(self, url=None, request_params=None)[source]¶ Make http-request using :package:`aiohttp`.
-
-
class
acg.parsers.AsyncReverso[source]¶ Bases:
acg.parsers.AsyncParserUse Reverso to obtain: examples.
-
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.
Return dict in a form as used in
custom_widgets.CustomSpeedDial.button_dicts.
-
-
exception
acg.parsers.NoMatchError(site='')[source]¶ Bases:
ExceptionError 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_urlformatted with all class attributes.
-
headers[source]¶ Headers for the request. Defaults to
DEFAULT_HEADERS.
-
make_request(self, url=None)[source]¶ Use
headersto make an http-request viaget().Parameters: url – If None, will be set to format_url_with_attribs(). (Default value = None)Returns: Responseobject
-
parse_response(self, response: requests.Response)[source]¶ Parse
requests.responseand return dict with result.
-
result_dict(self, phrase=None)[source]¶ Use
make_request()andparse_request()to return dict with result.
-
setup(self)[source]¶ Stuff that needs to be executed before
format_url_with_attribs()is called.
-
-
class
acg.parsers.RandTopicWikiParser[source]¶ Bases:
acg.parsers.ParserGet title, summary and a list of image-urls for given random topic.
-
acg.parsers.get_random_wiki_topic(category)[source]¶ Return page-string for a random page in a category.