指向FluidTopics的HTML连接器
antidot-html-connector的Python项目详细描述
HTML连接器
通过此连接器,可以从将HTML文件发布到Fluid Topics租户 本地机器或任何可以运行python3的机器。它会自动创建一个表 基于HTML文件内容的内容。结果应该是 内容一经处理就可以在Fluid主题中使用。在
示例
对于HTML文件lorem.html
:
和一个流动的主题租户在我的.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
发布运行在知识中心可见:
文档将发布到流体主题,并自动生成目录:
安装
客户
有必要有一个工作的本地python3环境。在
例如,如果运行MacOs,则需要使用brew install pip3
安装pip3。在
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)
发展
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
- 项目
标签: