Question String pour récupération de valeurs

Plus d'informations
il y a 9 ans 1 semaine #23625 par boutou
Hello tout le monde, j'ai un petit soucis avec un script qui réupère des valeurs depuis un mail et qui les convertit en Euros.

Et voilà mon script qui me retourne des erreurs \"can not read data\" pourtant quand je le fais ligne par ligne je n'ai pas de soucis...

j'ai mis un screenshot du mail que je reçois tous les jours car les fichiers msg ne peuvent être postés :-(

[code:1]#import exchange web service module
Import-Module EWSMail
#indicate if the debug mode is activated
$debugMode = $FALSE
#email will be sent to this address when debug mode is activated
$debugEmail = \"IT_Alert@xxxx.xxxg\"
#smtp server
$smtpSvr = \"smtp.xxx.xxx\"
#email address to use when sending logs
$logsEmailFrom = \"noreply@xxx.xxx\"
#email address to use when sending logs
$logsEmailAddress = if ($debugMode) {$debugEmail} else {\"IT_Alert@xxx.xxx\"}
#email subject to use when sending logs
$logsEmailSubject = \"[Currencies] Daily import from email\"
#email body to use when sending logs
$global:logsEmailBody = if ($debugMode) {\"DEBUG MODE ON\"} else {\"\"}

#full path to the folder where logs will be stored
$logFolder = \"C:\Scripts\Logs\CurrenciesFromEmail\"
#full path to the current log file
$global:logFile = \"$logFolder\\" + (get-date -format \"yyyyMMdd\"«») + \".log\"

#subject of email that have to be read
$mailSubject = \"Today's Currency Update (EUR)\"
#mailbox that have to be read
$mailAddress = \"currency@xxxx.xxx\"
#folder that has to be read within the mailbox
$mailFolderSource = \"Inbox\"
#folder in which to put treated emails within the mailbox
$mailFolderTarget = \"DeletedItems\"

#indicate whether an error has been detected
$global:errorTrigger = $FALSE

#add a log to the full log body
#Param
# pLogType type of the log to write
# pLogMessage log message to write
Function AddLog ($pLogType, $pLogMessage) {
$tmpDate = get-date -format \"HH:mm:«»ss\"
$global:logsEmailBody = @\"
$global:logsEmailBody
$tmpDate - $pLogType - $pLogMessage
\"@
If ($pLogType -eq \"ERROR\"«») {
$global:errorTrigger = $TRUE
}
Write-Host “$tmpDate - $pLogType - $pLogMessage”
}

#needed operations to end the script
Function EndScript() {
If ($global:errorTrigger -or $debugMode) {
Send-MailMessage -from $logsEmailFrom -smtpserver $smtpSvr -to $logsEmailAddress -subject $logsEmailSubject -Body $global:logsEmailBody
}
exit
}

#get first email
$mailCurrency = Get-EWSMailMessage -Mailbox $mailAddress -Folder $mailFolderSource -ResultSize 1

While ($mailCurrency.Subject) {
$tmpSubject = $mailCurrency.Subject
$tmpDate = $mailCurrency.Received
#if subject corresponds to subject for currency rates email
If ($tmpSubject.Equals($mailSubject)) {
#get reference date
$dateRef = $mailCurrency.Body.Text.Substring($mailCurrency.Body.Text.IndexOf(\"Rates as of\"«») + 12,20)
$dateRefNum = $dateRef.Substring(0,10).Replace('-','')
#get currencies table
$currencies = $mailCurrency.Body.Text.Substring($mailCurrency.Body.Text.IndexOf(\"Top 85 Currencies\"«»)).split(\"`n\"«»)
#go through currencies table
$ligneNb = 0
While ($ligneNb -lt 85) {
try {
#define current line to read
$ligneCurrent = 14 + ($ligneNb * 10)
$ligneCurrent
#get currency code
$currencyCode = $currencies[$lignecurrent].Trim().substring(0,3)
#get currency name
$currencyName = $currencies[$lignecurrent].Trim().substring(4)
#get currency rate
$rateValueEur = $currencies[$lignecurrent + 3].Trim().Replace(\",\",\"\"«»)
$rateValueFr = [float]$rateValueEur * 6.55957

} catch {
AddLog \"ERROR\" \"$tmpSubject ($tmpDate) - cannot read data: $dateRef[$currencyCode]=$rateValueEur ($rateValueFr,$dateRefNum) - $tmpvar\"
} finally {
$ligneNb++
}
}
} else {
try {
#forward message to logs mail address
Send-MailMessage -from $mailCurrency.From -smtpserver $smtpSvr -to $logsEmailAddress -subject $tmpSubject -Body $mailCurrency.Body
AddLog \"infos\" \"$tmpSubject ($tmpDate) has been forwarded to $logsEmailAddress\"
} catch {
AddLog \"ERROR\" \"$tmpSubject ($tmpDate) cannot be forwarded to $logsEmailAddress\"
}
}
try {
#move treated message in the target folder
#$tmpMove = Move-EWSMailMessage -Id $mailCurrency.Id -Mailbox $mailAddress -Confirm:$FALSE -TargetFolder $mailFolderTarget
AddLog \"infos\" \"$tmpSubject ($tmpDate) has been moved to the $mailFolderTarget folder\"
} catch {
AddLog \"ERROR\" \"$tmpSubject ($tmpDate) cannot be moved to the $mailFolderTarget folder\"
}
#get next email
$mailCurrency = Get-EWSMailMessage -Mailbox $mailAddress -Folder $mailFolderSource -ResultSize 1
}
Endscript[/code:1]


Le problème se situe dans la partie en gras dans le script.

J'ai retiré la partie SQL pour que ce soit plus lisible. Si quelqu'un pouvait me venir en aide, car là je bloque sérieusement...
Merci à tous !<br><br>Message édité par: boutou, à: 15/05/17 13:01
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 1 semaine #23626 par boutou
Voilà le fichier que je reçois par email (en pj)

La pièce jointe today__s_currency.zip est absente ou indisponible

<br><br>Message édité par: boutou, à: 15/05/17 13:03
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.048 secondes
Propulsé par Kunena