将HTML发布到telegra.ph博客服务

html-telegraph-poster的Python项目详细描述


Build Status

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")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javajexcel包装文本问题   EclipseJavaEnum缩进超过左括号。如何让它看起来更正常?   java有办法包含Tomcat 6 catalina。out和localhost。在网络应用的日志文件中记录内容?   java如何永久性地阻止JavaFX代码在eclipse中被突出显示为错误?   如何在java中优化两个for循环(for循环中的for循环)   java如何在我的windows机器上从jar文件创建mac osx的可执行文件   使用记忆化/动态规划的Java组合学   Java中的游荡对象垃圾收集   java为什么我在JSP和JDBC和MySQL中遇到连接失败错误   java轮询Pod的就绪状态   如何创建电子邮件并将其发送到Java中的特定地址?   java如何修复Dagger 2错误“。。。无法提供[…]”?   java Android单选按钮看起来太轻   Android Studio:开发在应用程序之间共享的通用java库