Hier mal eine kleine Übersicht des Scripts:
AutoIt
#include <_StringBetween2.au3>
#include <_StringSplitRegExp.au3>
#include <File.au3>
#include <Array.au3>
$SmtpServer = "smtp.mail.yahoo.com" ; address for the smtp-server to use - REQUIRED
$FromName = "XXXXXXXXXX" ; name from who the email was sent
$FromAddress = "XXXXXXXXXXXXXXXXX" ; address from where the mail should come
$ToAddress = "XXXXXXXXXXXXXXX" ; destination address of the email - REQUIRED
$Subject = "" ; subject from the email - can be anything you want it to be
$Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = "" ; address for cc - leave blank if not needed
$BccAddress = "" ; address for bcc - leave blank if not needed
$Importance = "High" ; Send message priority: "High", "Normal", "Low"
$Username = "XXXXXXXXXXXXXXX" ; username for the account used from where the mail gets sent - REQUIRED
$Password = "XXXXXXXXXXXX" ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 465 ; port used for sending the mail
$ssl = 1
While 1
_Read()
Sleep(5000)
WEnd
Func _Read()
$GM = "GMUNDEN"
$VB = "VÖCKLABRUCK"
_GetData($GM)
_GetData($VB)
EndFunc ;==>_Read
Func _GetData($var1)
Global $String = Execute("'" & StringRegExpReplace(BinaryToString(InetRead("http://intranet.ooelfv.at/webext2/getjson.php?scope=laufend&callback=", 1), 1), "(\\u([[:xdigit:]]{4}))", "' & ChrW(0x$2) & '") & "'") ;<======= LAUFEND
$StrSpl_RAW = _StringSplitRegExp($String, '"einsatz"')
ConsoleWrite(@CR & "Scan für Einsätze mit Stichwort: " & $var1 & " => gestartet")
For $a = 1 To UBound($StrSpl_RAW) - 1
Sleep(50)
ConsoleWrite(@CR & "Durchsucht: " & $a & " von " & UBound($StrSpl_RAW) - 1)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], '"', "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], '}', "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], '{', "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ')', "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ';', "")
$StrSpl_RAW[$a] = StringRegExpReplace($StrSpl_RAW[$a], ":", "", 1)
$StrLen = StringLen($StrSpl_RAW[$a])
$LastDigit = StringMid($StrSpl_RAW[$a], $StrLen)
$Alpha = StringIsAlpha($LastDigit)
While $Alpha = 0
$StrSpl_RAW[$a] = StringTrimRight($StrSpl_RAW[$a], 1)
$StrLen = $StrLen - 1
$LastDigit = StringMid($StrSpl_RAW[$a], $StrLen)
$Alpha = StringIsAlpha($LastDigit)
WEnd
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ",", ".", 5)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ".", ",", 4)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ",", ".", 3)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ".", ",", 2)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "=", ":")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ",", "|")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "wgs84:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ".status:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "cntfeuerwehren", "anzahl")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "feuerwehren:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "id:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "default:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "text", "einsatzbezeichnung", 1)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "text", "einsatzsubbezeichnung", 1)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "text", "bezirkbezeichnung", 1)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "estnum", "straßennummer", 1)
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "default:", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], ":", "")
$StrSpl_RAW[$a] = StringReplace($StrSpl_RAW[$a], "\", "")
$StrSpl_RAW[$a] = StringUpper($StrSpl_RAW[$a])
$StrSpl_DETAIL = StringSplit($StrSpl_RAW[$a], "|", 2)
Select
Case StringRegExp($StrSpl_RAW[$a], $var1) = 1
;~ _ArrayDisplay($StrSpl_DETAIL)
For $d = 0 To UBound($StrSpl_DETAIL) - 1
$StrSpl_DETAIL[$d] = StringReplace($StrSpl_DETAIL[$d], ":", "")
Select
Case StringRegExp($StrSpl_DETAIL[$d], "NUM1") = 1
$NUMMER = StringReplace($StrSpl_DETAIL[$d], "NUM1", "", 1)
If FileExists(@ScriptDir & "\data\old\" & $NUMMER & ".txt") = 1 Then
ExitLoop
EndIf
ConsoleWrite(@CR & "- " & $NUMMER)
Case StringRegExp($StrSpl_DETAIL[$d], "EINSATZORT") = 1
$EINSATZORT = StringReplace($StrSpl_DETAIL[$d], "EINSATZORT", "Einsatzort: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $EINSATZORT)
ConsoleWrite(@CR & "- " & $EINSATZORT)
Case StringRegExp($StrSpl_DETAIL[$d], "EINSATZSUBBEZEICHNUNG") = 1
$EINSATZSUBBEZEICHNUNG = StringReplace($StrSpl_DETAIL[$d], "EINSATZSUBBEZEICHNUNG", "Info: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $EINSATZSUBBEZEICHNUNG)
ConsoleWrite(@CR & "- " & $EINSATZSUBBEZEICHNUNG)
Case StringRegExp($StrSpl_DETAIL[$d], "ADRESSE") = 1
$ADRESSE = StringReplace($StrSpl_DETAIL[$d], "ADRESSE", "Adresse: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $ADRESSE)
ConsoleWrite(@CR & "- " & $ADRESSE)
Case StringRegExp($StrSpl_DETAIL[$d], "FEUERWEHR") = 1
$FEUERWEHR = StringReplace($StrSpl_DETAIL[$d], "FEUERWEHR", "Feuerwehr: ")
$FEUERWEHR = StringRegExpReplace($FEUERWEHR, "\d", "")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $FEUERWEHR)
ConsoleWrite(@CR & "- " & $FEUERWEHR)
Case StringRegExp($StrSpl_DETAIL[$d], "ALARMSTUFE") = 1
$ALARMSTUFE = StringReplace($StrSpl_DETAIL[$d], "ALARMSTUFE", "Alarmstufe: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $ALARMSTUFE)
ConsoleWrite(@CR & "- " & $ALARMSTUFE)
Case StringRegExp($StrSpl_DETAIL[$d], "STARTZEIT") = 1
$STARTZEIT = StringReplace($StrSpl_DETAIL[$d], "STARTZEIT", "Einsatzbeginn: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $STARTZEIT)
ConsoleWrite(@CR & "- " & $STARTZEIT)
Case StringRegExp($StrSpl_DETAIL[$d], "ECOMPL") = 1
$INFO = StringReplace($StrSpl_DETAIL[$d], "ECOMPL", "Freitext: ")
FileWriteLine(@ScriptDir & "\data\new\" & $NUMMER & ".txt", $INFO)
ConsoleWrite(@CR & "- " & $INFO)
EndSelect
Next
ConsoleWrite(@CR & "- " & $a & " SUCCESS")
If FileExists(@ScriptDir & "\data\old\" & $NUMMER & ".txt") = 0 Then
ConsoleWrite(@CR & "- ############ Versendet! nr.: " & $NUMMER & " #############################")
Local $ReadFile = FileRead(@ScriptDir & "\data\new\" & $NUMMER & ".txt")
;~ MsgBox(0,"LFK-News",$ReadFile)
$Body = $ReadFile
$Subject = "Neuer Einsatz! Nr.: "&$NUMMER
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
EndIf
FileMove(@ScriptDir & "\data\new\" & $NUMMER & ".txt", @ScriptDir & "\data\old\" & $NUMMER & ".txt")
EndIf
EndSelect
Next
ConsoleWrite(@CR & "Scan für Einsätze mit Stichwort: " & $var1 & " => beendet")
EndFunc ;==>_GetData
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
Local $objEmail = ObjCreate("CDO.Message")
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
$objEmail.HTMLBody = $as_Body
Else
$objEmail.Textbody = $as_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
If FileExists($S_Files2Attach[$x]) Then
ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
SetError(1)
Return 0
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
If Number($IPPort) = 0 Then $IPPort = 25
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
;Authenticated SMTP
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $ssl Then
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
;Update settings
$objEmail.Configuration.Fields.Update
; Set Email Importance
Switch $s_Importance
Case "High"
$objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
Case "Normal"
$objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
Case "Low"
$objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
EndSwitch
$objEmail.Fields.Update
; Sent the Message
$objEmail.Send
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
$objEmail = ""
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
Alles anzeigen
Noch in arbeit, aber vielleicht hat jemand Verbesserungsvorschläge und außerdem gehört es sich ja wohl auch, denn eigentlich betreffenden Code zu posten, nachdem man Hilfe dafür bekommen hat
Schöne Grüße, Stoani