telegraph package

telegraph.api module

class telegraph.api.Telegraph(access_token=None)[source]

Bases: object

Telegraph API client helper

Parameters

access_token – Telegraph access token

create_account(short_name, author_name=None, author_url=None, replace_token=True)[source]

Create a new Telegraph account

Parameters
  • short_name – Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the “Edit/Publish” button on Telegra.ph, other users don’t see this name

  • author_name – Default author name used when creating new articles

  • author_url – Default profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channels

  • replace_token – Replaces current token to a new user’s token

create_page(title, content=None, html_content=None, author_name=None, author_url=None, return_content=False)[source]

Create a new Telegraph page

Parameters
  • title – Page title

  • content – Content in nodes list format (see doc)

  • html_content – Content in HTML format

  • author_name – Author name, displayed below the article’s title

  • author_url – Profile link, opened when users click on the author’s name below the title

  • return_content – If true, a content field will be returned

edit_account_info(short_name=None, author_name=None, author_url=None)[source]
Update information about a Telegraph account.

Pass only the parameters that you want to edit

Parameters
  • short_name – Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the “Edit/Publish” button on Telegra.ph, other users don’t see this name

  • author_name – Default author name used when creating new articles

  • author_url – Default profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channels

edit_page(path, title, content=None, html_content=None, author_name=None, author_url=None, return_content=False)[source]

Edit an existing Telegraph page

Parameters
  • path – Path to the page

  • title – Page title

  • content – Content in nodes list format (see doc)

  • html_content – Content in HTML format

  • author_name – Author name, displayed below the article’s title

  • author_url – Profile link, opened when users click on the author’s name below the title

  • return_content – If true, a content field will be returned

get_access_token()[source]

Get current access_token

get_account_info(fields=None)[source]

Get information about a Telegraph account

Parameters

fields

List of account fields to return. Available fields: short_name, author_name, author_url, auth_url, page_count

Default: [“short_name”,“author_name”,“author_url”]

get_page(path, return_content=True, return_html=True)[source]

Get a Telegraph page

Parameters
  • path – Path to the Telegraph page (in the format Title-12-31, i.e. everything that comes after https://telegra.ph/)

  • return_content – If true, content field will be returned

  • return_html – If true, returns HTML instead of Nodes list

get_page_list(offset=0, limit=50)[source]
Get a list of pages belonging to a Telegraph account

sorted by most recently created pages first

Parameters
  • offset – Sequential number of the first page to be returned (default = 0)

  • limit – Limits the number of pages to be retrieved (0-200, default = 50)

get_views(path, year=None, month=None, day=None, hour=None)[source]

Get the number of views for a Telegraph article

Parameters
  • path – Path to the Telegraph page

  • year – Required if month is passed. If passed, the number of page views for the requested year will be returned

  • month – Required if day is passed. If passed, the number of page views for the requested month will be returned

  • day – Required if hour is passed. If passed, the number of page views for the requested day will be returned

  • hour – If passed, the number of page views for the requested hour will be returned

revoke_access_token()[source]

Revoke access_token and generate a new one, for example, if the user would like to reset all connected sessions, or you have reasons to believe the token was compromised. On success, returns dict with new access_token and auth_url fields

upload_file(f)[source]
Upload file. NOT PART OF OFFICIAL API, USE AT YOUR OWN RISK

Returns a list of dicts with src key. Allowed only .jpg, .jpeg, .png, .gif and .mp4 files.

Parameters

f (file, str or list) – filename or file-like object.

class telegraph.api.TelegraphApi(access_token=None)[source]

Bases: object

Telegraph API Client

Parameters

access_token (str) – access_token

access_token
method(method, values=None, path='')[source]
session
upload_file(f)[source]
Upload file. NOT PART OF OFFICIAL API, USE AT YOUR OWN RISK

Returns a list of dicts with src key. Allowed only .jpg, .jpeg, .png, .gif and .mp4 files.

Parameters

f (file, str or list) – filename or file-like object.

telegraph.upload module

telegraph.upload.upload_file(f)[source]

Deprecated, use Telegraph.upload_file

telegraph.utils module

class telegraph.utils.FilesOpener(paths, key_format='file{}')[source]

Bases: object

close_files()[source]
open_files()[source]
class telegraph.utils.HtmlToNodesParser[source]

Bases: html.parser.HTMLParser

add_str_node(s)[source]
get_nodes()[source]
handle_charref(name)[source]
handle_data(data)[source]
handle_endtag(tag)[source]
handle_entityref(name)[source]
handle_starttag(tag, attrs_list)[source]
telegraph.utils.html_to_nodes(html_content)[source]
telegraph.utils.json_dumps(*args, **kwargs)[source]
telegraph.utils.nodes_to_html(nodes)[source]