Skip to content

Python wrapper for the Telegraph blogging service provided by Telegram

License

Notifications You must be signed in to change notification settings

jacoduplessis/telegraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Python wrapper for the Telegraph blogging service provided by Telegram

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages