Python wrapper for the Telegraph blogging service provided by Telegram
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
telegraph
tests
.gitignore
LICENSE
changelog.md
readme.md
setup.py Bump version Feb 11, 2019

readme.md

Telegraph

Documentation Status

Python wrapper for the Telegraph blogging service provided by Telegram

Requires Python 3.6+.

A more-or-less direct mapping to the Telegraph API, with snake_case instead of camelCase.

Documentation

The documentation on RTD is broken until they support Python3.6.

To build and view the docs locally:

pip install sphynx
cd docs
make html
cd build
python -m http.server 8010

Install

pip install telegraph_client

Usage

from telegraph import Telegraph

# using existing account
telegraph = Telegraph('<access_token>')
# or with new account
account = telegraph.create_account(short_name='Ludo Loeloeraai', use=True)
# set use=False if using an authenticated client to create new accounts without switching to them

# get pages
page_list = telegraph.get_page_list(offset=0, limit=100)
num_pages = page_list.total_count
for page in page_list.pages:
    print(page.title, page.url)
    
# create page
new_page = telegraph.create_page(title="New Page", content=['Lorem Ipsum'])
assert new_page.title == "New Page"

Utilities

Two helper functions are included to render page content and serialize html into the required format.

First install the required dependencies:

pip install beautifulsoup4 bleach

from telegraph import Telegraph
from telegraph.utils import content_to_html, html_to_content

telegraph = Telegraph('<access_token>')

# rendering page content as html
page = telegraph.get_page('<path>')
html = content_to_html(page.content)

# creating a page from html string
html_string = '<p>Hallo, World!</p>'
content = html_to_content(html_string)
telegraph.create_page(title="Test", content=content)

Tests

python -m unittest discover tests