How to use Python keynote-parser in the Azure Functions

120 Views Asked by At

I am trying to use an external module called keynote-parser to extract data from the a Mac Keynote file. It works when I use as command lines in the terminal on the Mac laptop locally. I am trying to extract the data and put the files/blobs into a Azure Storage (Blob/Fileshare) using the Keynote-parser. However, I am not quite sure how to write the script to include the keynote-parser and then calling. Honestly, I am stuck even having it as a local Python script even run it instead of command lines.

here is the keynote-parser https://github.com/psobot/keynote-parser

I expected it to able to pickup a file/blob from Azure Storage (fileshare/blob) and extract the files. The script will then select the output file called Slide.iwa.yaml from the index folder it generated. The script will put the file into Azure Storage (fileshare/blob).

When having just import keynote_parser, no issue. However, when added from keynote_parser import file utils, the deployment out shows that "No HTTP triggers found"

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.')
1

There are 1 best solutions below

1
Ikhtesam Afrin On BEST ANSWER

I have used from keynote_parser import file_utils in my code and then published it to function app like below-

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

I have deployed the function and got successful deployment result.

enter image description here

For No HTTP triggers found, you can check the following-

  • If you have added any connection string in function_app.py file then move it to local.settings.json file and refer it.
  • Check in the function app-->Environment Variables, if "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" is present.

You can also refer to this github issue for more details on No HTTP triggers found.

Output:

enter image description here