Skip to main content
Flight Specialist | Tier 4
December 17, 2024
Question

How to optimize unicode formatting

  • December 17, 2024
  • 5 replies
  • 94 views

Hi everyone,

 

I have created a bot that retrieves e-mails with the Microsoft Graph API. However, the result must be properly encoded using unicode. For example the letter “è” is U+00E8 and if I don’t correct it, the word “règlement” appears as “ru00e8glement“

I have used the javascript component, to run this function :

 

function decodeUnicode(str) {
    return str.replace(/\\u[\dA-F]{4}/gi, function(match) {
        return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
    });
}

 

However, it is particularly slow.

If I run this script on a batch of 100 e-mails, it takes roughly two minutes. In my opinion, it is not an acceptable duration. Is there a way to optimize that ?

5 replies

AugustinAuthor
Flight Specialist | Tier 4
December 17, 2024

Update : it is equally slow in vbscript, and does not work in python (why ? no idea, there is no logging/no information on why it fails)

AugustinAuthor
Flight Specialist | Tier 4
December 17, 2024

I ended up doing a String:replace for every character I found could appear (I have more or less 40 lines of String:replace commands) and it takes less than 10 seconds.

It is really awful for the javascript component to be that inefficient

Aaron.Gleason
Automation Anywhere Team
Automation Anywhere Team
December 17, 2024

We have several email functions that are already Unicode safe. Are you using the right tool for the job?

AugustinAuthor
Flight Specialist | Tier 4
December 17, 2024

We have several email functions that are already Unicode safe. Are you using the right tool for the job?

The end-user customer won’t let us use the IMAP functions, I have no choice but to use the Microsoft graph API.

Aaron.Gleason
Automation Anywhere Team
Automation Anywhere Team
December 17, 2024

Stepping back, there is logging for Python in the bot runner logs.

C:\ProgramData\AutomationAnywhere\BotRunner\Logs

Look through the Node Manager for that info. Python, JavaScript and those are handed to the OS. I’m surprised it is that slow.

A quick glance online shows the FTFY library in Python could help solve your issue.