REST Api Wrapper

Telegraph class

class telegraph_api.Telegraph(access_token=None)

Telegraph API class

__init__(access_token=None)

Constructor of Class

Parameters

access_token – Access token. If not specified, limited quanity of methods will be availible, until you create account

async create_account(short_name: str, author_name: Optional[str] = None, author_url: Optional[str] = None, renew_token: bool = True)

Method for Creating new Account.

Parameters
  • short_name – Account name, helps users with several accounts remember which they are currently using

  • author_name – Default author name used when creating new articles.

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

  • renew_token – Specifies, should be Telegraph object token renewed on method execution

Returns

Account object with access_token field

async create_page(title: str, content: Optional[List[Node]] = None, author_name: Optional[str] = None, author_url: Optional[str] = None, return_content: bool = False, content_html: Optional[str] = None) Page

Create new telegraph page

Parameters
  • title – Page title

  • content – Content of the page

  • 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, content will be returned in content field

  • content_html – Html Content, that will be converted into list of nodes

Returns

Page object, contains content if return_content is set to True

async edit_account_info(short_name: Optional[str] = None, author_name: Optional[str] = None, author_url: Optional[str] = None) Account

Use this method to update information about a Telegraph account.

Parameters
  • short_name – New account name

  • author_name – New default author name used when creating new articles

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

Returns

an Account object with the default fields

async edit_page(path: str, title: str, content: Optional[List[Node]] = None, content_html: Optional[str] = None, author_name: Optional[str] = None, author_url: Optional[str] = None, return_content: bool = False) Page

Edit existing telegraph page

Parameters
  • path – Path to page

  • title – Page title

  • content – Content of the page

  • 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, content will be returned in content field

  • content_html – Html Content, that will be converted into list of nodes

Returns

Page object, contains content if return_content is set to True

async get_account_info(fields: Optional[List[str]] = None)

Use this method to 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

Returns

an Account object

async get_page(path: str, return_content: bool = False) Page

Use this method to revoke access_token and generate a new one

Parameters
  • path – Path to the Telegraph page

  • return_content – If true, content field will be returned

Returns

Page object

async get_views(path: str, year: Optional[int] = None, month: Optional[int] = None, day: Optional[int] = None, hour: Optional[int] = None) int

Use this method to 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.

Returns

By default, the total number of page views will be returned.

async revoke_access_token() dict

Use this method to revoke access_token and generate a new one. Sets new access_token

Returns

Account object with access token field

async upload_file(file_path: Optional[str] = None, file_stream: Optional[IO] = None)

Uploads file to telegra.ph servers (only gif, jpg, jpe, jpeg, jfif, png, mp4, m4v, mp4v files allowed)

Parameters
  • file_path – Path to file in local filesystem

  • file_stream – IO object for example can be occurred from open() function

Returns

UploadedFile object

Raises
  • FileIsNotPresented – If no files were passed into function

  • InvalidFileExtension – If file extension is not supported by telegra.ph