将HTML发布到telegra.ph博客服务
html-telegraph-poster的Python项目详细描述
python html到telegra.ph海报
简单的python函数将纯html文本发布到https://telegra.ph/。
telegra.ph允许<a>, <blockquote>, <br>, <em>, <figure>, <h3>, <h4>, <img>, <p>, <strong>,
元素。
它还支持嵌入的youtube和vimeo iframe标签。
关于telegra.ph服务https://telegram.org/blog/instant-view
要求
- lxml
- 请求
- 请求工具带
安装
pip install html-telegraph-poster
用法
>>>fromhtml_telegraph_posterimportTelegraphPoster>>>t=TelegraphPoster()>>>t.create_api_token('Elon Musk','Elon','https://www.spacex.com/')# second and third params are optional{'access_token':'9f3bab568f*************','auth_url':'https://edit.telegra.ph/auth/HFYo***********','author_name':'Elon','short_name':'Elon Musk','author_url':'https://www.spacex.com/'}>>>t.post(title='Just another funny joke',author='by me',text='<blockquote>Really hard way</blockquote>'){'url':'https://telegra.ph/Just-another-funny-joke-12-05','path':'Just-another-funny-joke-12-05','tph_uuid':'4gFlYHCFiIBAxk***********','page_id':'a38*************'}# We can modify this article later>>>t.edit(text=t.text+'<p>some text at the end</p>'){'url':'https://telegra.ph/Just-another-funny-joke-12-05','path':'Just-another-funny-joke-12-05','tph_uuid':'4gFlYHCF*********','page_id':'a381b2********'}
生成永久访问令牌
实际上,最好生成访问令牌并将其放入环境变量中。
此命令将生成.env文件或在文件末尾附加电报访问令牌。
注意:脚本不会设置环境变量。你可以用python-dotenv,
手动设置或在调用TelegraphPoster(access_token='access_token_string')
python -m html_telegraph_poster.create_account "Elon Musk""Elon""https://www.spacex.com/"
上载图像
fromhtml_telegraph_poster.upload_imagesimportupload_image# upload fileupload_image("file_path.jpg")#upload urlupload_image("http://example.com/img.png")