指向FluidTopics的HTML连接器

antidot-html-connector的Python项目详细描述


HTML连接器

通过此连接器,可以从将HTML文件发布到Fluid Topics租户 本地机器或任何可以运行python3的机器。它会自动创建一个表 基于HTML文件内容的内容。结果应该是 内容一经处理就可以在Fluid主题中使用。在

示例

对于HTML文件lorem.html

HTML to import

和一个流动的主题租户在我的.fluidtopics.tenant.url。 必须有一个工作的本地Python环境,并且 已安装HTML连接器(请参阅“安装”)。在

# Send "lorem.html" to the FT tenant
html2ft lorem.html --url my.fluidtopics.tenant.url --login my@ddress.com --password mypassword

发布运行在知识中心可见:

Content processing

文档将发布到流体主题,并自动生成目录:

lorem in Fluid topics

安装

客户

有必要有一个工作的本地python3环境。在

例如,如果运行MacOs,则需要使用brew install pip3安装pip3。在

^{pr2}$

FT服务器

添加ID=HTMLConnector的外部源。拜托 让大家知道here 如果你不想那样做。在

使用

用作二进制文件

html2ft二进制文件将把HTML文档发布到Fluid主题 租户,并自动创建其目录。在

html2ft path/to/file.html --url my.fluidtopics.tenant.url --login my@ddress.com

可以添加--verbose--password myStr0ngP@ssword选项。在

用作库

直接发送至FT

要将数据直接发送到流体主题,请执行以下操作:

fromantidot.connector.htmlimportpublish_htmlpublish_html("path/to/file.html","my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword")

也可以使用fluidtopics包中的客户机对象:

fromfluidtopics.connectorimportRemoteClientfromantidot.connector.htmlimportpublish_html_with_clientclient=RemoteClient("my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword","mySourceID")publish_html_with_client("path/to/file.html",client=client)

获取中间发布对象

要从HTML文件获取出版物,请执行以下操作:

fromantidot.connector.htmlimporthtml_to_fluid_apipublication=html_to_fluid_api("path/to/file.html","Publication title")

使用返回发布的函数时,可以使用修饰符 对于连接:

fromdatetimeimportdatetimefromfluidtopics.connectorimportLoginAuthentication,Metadata,Publication,RemoteClientfromantidot.connector.generic.decoratorsimportClientAuthentication,LoginAndPasswordAuthenticationfromantidot.connector.htmlimporthtml_to_fluid_apiurl="my.fluidtopics.tenant.url"login="my@ddress.com"password="myStr0ngP@ssword"source_id="MySourceId"@ClientAuthentication(RemoteClient(url,LoginAuthentication(login,password)),source_id)defhtml_to_fluid_api_ftml_plugin(html_path)->list[Publication]:metadatas=[Metadata.last_edition(datetime.now().strftime("%Y-%m-%d")),Metadata.string("uploader",["ClientAuthentication"]),Metadata.string("use_ftml",["Yes"]),]returnhtml_to_fluid_api(html_path=html_path,metadatas=metadatas,use_ftml=True)@LoginAndPasswordAuthentication(url,login,password,source_id)defhtml_to_fluid_api_plugin(html_path)->list[Publication]:metadatas=[Metadata.last_edition(datetime.now().strftime("%Y-%m-%d")),Metadata.string("uploader",["LoginAndPasswordAuthentication"]),Metadata.string("use_ftml",["No"]),]returnhtml_to_fluid_api(html_path=html_path,metadatas=metadatas,use_ftml=False)

可选参数

呈现封面

“渲染”封面页选项可用。在

fromfluidtopics.connectorimportRemoteClientfromantidot.connector.htmlimporthtml_to_fluid_api,publish_html,publish_html_with_clientpublish_html("path/to/file.html","my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword",use_ftml=True)publish_html_with_client("path/to/file.html",RemoteClient("my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword","mySourceID"),use_ftml=True,)publication=html_to_fluid_api("path/to/file.html","My title",use_ftml=True)

对于二进制文件,它是--render-cover-page。在

添加元数据

还可以通过提供 包含metadatas参数的元数据列表:

fromdatetimeimportdatetimefromfluidtopics.connectorimportMetadata,RemoteClientfromantidot.connector.htmlimporthtml_to_fluid_api,publish_html,publish_html_with_clientuse_ftml=Truemetadatas=[Metadata.string("splitting_algorithm",["ftml"ifuse_ftmlelse"default"]),Metadata.last_edition(datetime.now().strftime("%Y-%m-%d")),]publish_html("path/to/file.html","my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword",use_ftml=use_ftml,metadatas=metadatas,)publish_html_with_client("path/to/file.html",RemoteClient("my.fluidtopics.tenant.url","my@ddress.com","myStr0ngP@ssword","mySourceID"),metadatas,use_ftml,)publication=html_to_fluid_api("path/to/file.html","Publication title",use_ftml=True,metadatas=metadatas)

可选FTML拆分算法

要发布FTML,还需要安装FTML连接器:

pip3 install antidot-fluidtopics-ftml-connector -i https://pypi.mrs.antidot.net/antidot/stable/

一旦安装了连接器,带有--use-ftml选项的二进制文件就可用了。在

要添加use_ftml参数:

fromantidot.connector.htmlimportpublish_html,publish_html_with_client,html_to_fluid_apifromfluidtopics.connectorimportRemoteClienturl="my.fluidtopics.tenant.url"login="my@ddress.com"password="myStr0ngP@ssword"source_id="MySourceId"html_path="path/to/file.html"title="My Title"publish_html(html_path,url,login,password,use_ftml=True)publish_html_with_client(html_path,RemoteClient(url,login,password,source_id),use_ftml=True)publication=html_to_fluid_api(html_path,title,use_ftml=True)

发展

coverage reportCode style: blackPRs Welcome

python3 -m venv venv
source venv/bin/activate
# Use
pip3 install -e .
html2ft -h
# Test
pip3 install -e ".[test]"
python3 -m pytest . --cov=antidot --cov-report html --verbose -vv
xdg-open htmlcov/index.html

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

推荐PyPI第三方库


热门话题
不同窗口中的java视图   java创建SQL插入语句到CSV文件   java效率检查:Opengl动画代码   在clojure中处理Java可选<T>   java理解camel中的输入/输出交换模式行为   对于使用jpackage构建的应用程序,java LSOpenURLsWithRole()失败,错误为10810   多线程Java同步:多重倒计时闩锁   java哪个类应该做这项工作?   java在运行时出现问题。getRuntime()。执行官   java我们不能在GAE中使用集合或集合作为返回类型吗?   amazon web服务返回类型与RequestHandler<Object,String>不兼容。JAVA中的HandlerRequest(对象、上下文)   如何在Java中使用ExecutorService设置任务的超时时间