Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mercuree/html-telegraph-poster
Python html to telegra.ph poster (telegram article service)
https://github.com/mercuree/html-telegraph-poster
python telegram telegraph
Last synced: 3 months ago
JSON representation
Python html to telegra.ph poster (telegram article service)
- Host: GitHub
- URL: https://github.com/mercuree/html-telegraph-poster
- Owner: mercuree
- License: mit
- Created: 2016-12-03T11:41:22.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T03:37:27.000Z (over 1 year ago)
- Last Synced: 2024-08-31T12:16:21.873Z (5 months ago)
- Topics: python, telegram, telegraph
- Language: Python
- Homepage:
- Size: 149 KB
- Stars: 97
- Watchers: 6
- Forks: 29
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-telegram-bots - html-telegraph-poster - Python html to telegra.ph poster (telegram article service) (Examples / Python)
README
[![build](https://github.com/mercuree/html-telegraph-poster/actions/workflows/python-package.yml/badge.svg)](https://github.com/mercuree/html-telegraph-poster/actions/workflows/python-package.yml)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/html-telegraph-poster?master)](https://pypi.org/project/html-telegraph-poster/)# Python html to telegra.ph poster
## Generate persistent access token
Actually it's a good idea to generate access token and put it inside environment variables.
This command will generate .env file or append TELEGRAPH_ACCESS_TOKEN at the end of it.
Note: script will not set environment variable. You can use [python-dotenv](https://github.com/theskumar/python-dotenv),
set it manually or hardcode it when call `TelegraphPoster(access_token='access_token_string')`
```Shell
python -m html_telegraph_poster.create_account "Elon Musk" "Elon" "https://www.spacex.com/"
```## Uploading images
```pythonfrom html_telegraph_poster.upload_images import upload_image
# upload file
upload_image("file_path.jpg")# upload url
upload_image("http://example.com/img.png")# setting request and response timeout
upload_image("http://example.com/img.png", get_timeout=(5, 5), upload_timeout=(5, 5))```
## Utils module
Utils module provides ability to make some pre-process steps before document is passed to the converter.
#### Uploading all images to the telegra.ph
```python
from html_telegraph_poster.utils import DocumentPreprocessordp = DocumentPreprocessor(html_string)
dp.upload_all_images()
dp.get_processed_html() # this should return html string with uploaded and replaced image urls
```
Optionally you can pass base_url if the document contains images with relative paths
```python
dp.upload_all_images(base_url='https://example.com')
dp.get_processed_html()
```