A Python library for interacting with the Telegraph API
Project description
Telegraph API Python Library
This Python library provides easy-to-use functions to interact with the Telegraph API, which allows you to create, edit, and manage Telegraph posts and accounts.
Features
- Create and manage Telegraph accounts.
- Create, edit, and retrieve pages.
- Fetch page view statistics.
- Revoke access tokens.
- Easily integrate with any Python project.
Installation
You can install the required dependencies using pip. Make sure you have Python installed.
pip install Telegraph-Uploader
Usage
Below is an example of how you can use the Telegraph API with this library.
from telegraph import TelegraphAPI
# Initialize API
telegraph_api = TelegraphAPI()
# Create a new account
account = telegraph_api.create_account(short_name="TestUser", author_name="Anonymous", author_url="https://example.com")
print(f"Account created: {account}")
# Access token for future requests
access_token = account['access_token']
# Initialize API with access token
telegraph_api = TelegraphAPI(access_token)
# Create a new page
content = [{"tag": "p", "children": ["This is a sample Telegraph page created via API."]}]
page = telegraph_api.create_page(title="Sample Page", content=content, author_name="Anonymous", return_content=True)
print(f"Page created: {page}")
# Fetch the page details
fetched_page = telegraph_api.get_page(page['path'], return_content=True)
print(f"Fetched page: {fetched_page}")
Methods
Account Management
create_account(short_name, author_name=None, author_url=None): Creates a new Telegraph account.edit_account_info(short_name=None, author_name=None, author_url=None): Updates account information.get_account_info(fields=None): Retrieves account information.revoke_access_token(): Revokes the current access token and generates a new one.
Page Management
create_page(title, content, author_name=None, author_url=None, return_content=False): Creates a new Telegraph page.edit_page(path, title, content, author_name=None, author_url=None, return_content=False): Edits an existing page.get_page(path, return_content=False): Fetches details of a specific page.get_page_list(offset=0, limit=50): Retrieves a list of pages belonging to the account.
Page Statistics
get_views(path, year=None, month=None, day=None, hour=None): Gets the number of views for a Telegraph page.
Error Handling
All errors returned by the Telegraph API are handled by raising TelegraphException. For example:
from telegraph.exceptions import TelegraphException
try:
account = telegraph_api.create_account(short_name="TestUser")
except TelegraphException as e:
print(f"An error occurred: {e}")
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegraph_uploader-1.0.tar.gz.
File metadata
- Download URL: telegraph_uploader-1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a27c316c204b300d1b07c32f39642a78f7a3c5b1c243f7796feeb25ec301b89
|
|
| MD5 |
bed5f5330a3785d78fad2f6c767e050e
|
|
| BLAKE2b-256 |
d7620952492188472e2aa2f495f6eb2b608d552d47e2083f7d42808bb16dc7ab
|
File details
Details for the file telegraph_uploader-1.0-py3-none-any.whl.
File metadata
- Download URL: telegraph_uploader-1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16c1248736a655bc4047f1fffe1f9fc0d6fbcbfce367182614945c3971f6a7ad
|
|
| MD5 |
b45ff26f94ffee66886e1d03f51c28b3
|
|
| BLAKE2b-256 |
0407bdb7caf45e1b49bdfdf469afd7eb1ffee325291839e919e361625f3997d7
|