Text analysis in Azure Logic applications

I want to create an Azure Logic App that will constantly query a specific site on the Internet and analyze the resulting HTML.

I created the Logic App and configured the interval and action of the HTTP request.

What action should be taken as the next step for a simple regex operation in HTML?

What comes to my mind is creating an Azure Function that will do the job, but I wonder if there is another solution that is more suitable for such a task.

I want it to be as simple as possible.


Edit:

Just found out some interesting feature. Logic applications contain some basic expressions for primitive types.

, regex string.contains.

Azure.

+5
5

, Azure.

Azure Function , , , , , .

.

, JSON

{
    "$connections": {
        "value": {
            "wunderlist": {
                "connectionId": "/subscriptions/.../providers/Microsoft.Web/connections/wunderlist",
                "connectionName": "wunderlist",
                "id": "/subscriptions/.../providers/Microsoft.Web/locations/northeurope/managedApis/wunderlist"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Condition": {
                "actions": {
                    "Create_a_task": {
                        "inputs": {
                            "body": {
                                "completed": false,
                                "list_id": 000000000,
                                "starred": true,
                                "title": "@{variables('today date')}"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['wunderlist']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/tasks",
                            "retryPolicy": {
                                "type": "none"
                            }
                        },
                        "limit": {
                            "timeout": "PT20S"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    },
                    "Set_a_reminder": {
                        "inputs": {
                            "body": {
                                "date": "@{addHours(utcNow(), 3)}",
                                "list_id": 000000,
                                "task_id": "@body('Create_a_task')?.id"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['wunderlist']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/reminders",
                            "retryPolicy": {
                                "type": "none"
                            }
                        },
                        "limit": {
                            "timeout": "PT20S"
                        },
                        "runAfter": {
                            "Create_a_task": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    }
                },
                "expression": "@contains(body('HTTP'), variables('today date'))",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "HTTP": {
                "inputs": {
                    "method": "GET",
                    "uri": "..."
                },
                "runAfter": {},
                "type": "Http"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "today date",
                            "type": "String",
                            "value": "@{utcNow('yyyy/MM/dd')}"
                        }
                    ]
                },
                "runAfter": {
                    "HTTP": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Day",
                    "interval": 1,
                    "startTime": "2017-08-01T23:55:00Z",
                    "timeZone": "UTC"
                },
                "type": "Recurrence"
            }
        }
    }
}
0

Azure Function :

{

log.Info( " # ".);

// Get request body

dynamic data = await req.Content.ReadAsAsync<object>();



// Set name to query string or body data

string input = data?.input.ToString();

var regexJson = data?.regexList;

var regexes = regexJson.ToObject<List<RegexReplace>>();



foreach (var regex in regexes) 

{

    var re = Regex.Replace(regex.Regex, "\\\\","\\");

    var replace = Regex.Replace(regex.Replace, "\\\\","\\");

    input = Regex.Replace(input, "\\\"","\"");

    input = Regex.Replace(input, re, replace);

}



input = Regex.Replace(input, "[\\r\\n]", "");



return data.regexList == null

    ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")

    : req.CreateResponse(HttpStatusCode.OK, input, "application/json");

}

public class RegexReplace

{

public string Regex { get; set; }

public string Replace { get; set; }

}

+1

, . Azure . API - , , .

0

. , :

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    dynamic data = await req.Content.ReadAsAsync<object>();
    string removeme = data?.removeme;
    string replacewith = data?.replacewith;
    string value = data?.value;

    return req.CreateResponse(HttpStatusCode.OK, value.Replace(removeme, replacewith));
}

:

{
    "removeme": "SKU-",
    "replacewith": "P-",
    "value": "SKU-37378633"
}

... : "P-37378633"

0

javascript ( ) ( Flow).

Iniline Code

Ref

0

Source: https://habr.com/ru/post/1682828/


All Articles