如何在 Azure Functions 中使用 Python keynote-parser

问题描述 投票:0回答:1

我正在尝试使用名为 keynote-parser 的外部模块从 Mac Keynote 文件中提取数据。当我在本地 Mac 笔记本电脑的终端中用作命令行时,它可以工作。我正在尝试使用 Keynote 解析器提取数据并将文件/blob 放入 Azure 存储(Blob/Fileshare)中。但是,我不太确定如何编写脚本来包含 keynote-parser 然后调用。老实说,即使将它作为本地 Python 脚本来运行它而不是命令行,我也遇到了困难。

这是主题解析器 https://github.com/psobot/keynote-parser

我希望它能够从 Azure 存储(文件共享/blob)中获取文件/blob 并提取文件。然后,该脚本将从它生成的索引文件夹中选择名为 Slide.iwa.yaml 的输出文件。该脚本会将文件放入 Azure 存储(文件共享/blob)中。

当只有

import keynote_parser
时,没问题。但是,添加后
from keynote_parser import file utils
,部署显示“未找到 HTTP 触发器”

import azure.functions as func
import logging
import keynote_parser
from azure.storage.fileshare import ShareClient
from azure.storage.blob import BlobServiceClient, BlobType
from keynote_parser import file_utils

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
python azure-functions extract keynote
1个回答
0
投票

我在代码中使用了

from keynote_parser import file_utils
,然后将其发布到功能应用程序,如下所示-

Code:

import  azure.functions  as  func
import  logging
from  azure.storage.blob  import  BlobServiceClient,BlobType
from  azure.storage.fileshare  import  ShareClient
from  keynote_parser  import  file_utils

app  =  func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="http_trigger")
def  http_trigger(req: func.HttpRequest) -> func.HttpResponse:

logging.info('Python HTTP trigger function processed a request.')

name  =  req.params.get('name')
if  not  name:
try:
req_body  =  req.get_json()
except  ValueError:
pass
else:
name  =  req_body.get('name')
if  name:
return  func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return  func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)

requirements.txt:

azure-functions
keynote-parser
azure-storage-blob
azure-storage-file-share

我已部署该功能并获得成功的部署结果。

enter image description here

对于

No HTTP triggers found
,您可以检查以下内容-

  • 如果您在 function_app.py 文件中添加了任何连接字符串,请将其移至 local.settings.json 文件并引用它。
  • 检查功能应用程序-->环境变量,是否存在
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"

您也可以参考这个github问题以获取更多关于

No HTTP triggers found
的详细信息。

Output:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.