ws.autopage module

class ws.autopage.AutoPage(api, title=None, fetch_titles=None)

Bases: object

A quick interface for maintaining automatic content on wiki pages.

Parameters:
  • api – an ws.client.api.API instance
  • title (str) – the title of the initial page to use
  • fetch_titles (set) – A set of titles whose content should be fetched from the wiki. These are the pages that will be updated later on; the page title should be switched by the set_title() method. If None is supplied, fetch_titles defaults to [title].
fetch_pages(titles)

Fetch content of given pages from the API. As an optimization, as many pages as possible should be fetched in a single query.

Parameters:titles (set) – set of page titles
set_title(title)

Set current title to title and parse its content. Unsaved changes to previous page will be lost. The content of the page should have been fetched by fetch_pages(), otherwise ValueError will be raised.

Parameters:title (str) – the page title
get_tag_by_id(tag, id)

Finds a tag in the wikicode of the current page with given ID.

Parameters:
  • tag (str) – The type of the Tag <mwparserfromhell.nodes.tag.Tag, e.g. "div" or "table".
  • id (str) – The value of the id attribute of the tag to be matched.
Returns:

A mwparserfromhell.nodes.tag.Tag instance if found, otherwise None.

is_old_enough(min_interval=datetime.timedelta(0), strip_time=False)

Checks if the page on the wiki is old enough to be updated again.

Parameters:
  • min_interval (datetime.timedelta) – Minimum desired interval between two consecutive updates.
  • strip_time (bool) – If True, time is stripped from the UTC timestamps and only the dates are compared.
Returns:

True if the wiki page is older than min_interval.

save(edit_summary, interactive=False, **kwargs)

Saves the updated wikicode of the page to the wiki.

Parameters:
  • edit_summary (str) – Summary of the change.
  • interactive (bool) – If True, calls ws.interactive.edit_interactive() to ask the user before making the change; otherwise calls API.edit directly.
  • kwargs – Additional keyword arguments passed to the API query.