Jump to content

Looping data from csv


nivek
 Share

Recommended Posts

I just need some guidence... This is what i am trying to do.

data.csv

---------------------------------------------------------

D5,TW,TW@p.com

D6,JJ,JE@p.com

D7,JR,JR@p.com

D8,LC,LC@p.com

ETC........

---------------------------------------------------------

REPORT

---------------------------------------------------------

read col1 row1 of data.csv (id)

send data that was read

send tab

send same data again

file \ save

read col2 row1 of data.csv (name first & Last)

send data

enter

read col3 row1 of data.csv (email address)

email

then repeat with next row until end of data.csv

----------------------------------------------------------

I have most of it (sends,email things like that), but the data from the file is what is getting me.

how do i pull the data from the file into the places it needs to be? I am not a programer just learning.

Thank You,

nivek

Link to comment
Share on other sites

This is what i have... scavenged from other scripts

#Include<file.au3>

#include <INet.au3>

DriveMapAdd("o:", "\\server\u\")

FileDelete ( "o:\TV_output.txt" )

run("driver.exe")

WinWait("Information System","Enter your User ID a")

Send("******{TAB}******")

send("{ENTER}")

WinWait("About INFORMATIO","BUS P")

Send(@TAb)

send("{ENTER}")

WinWait("PRODUCTS SYST","")

If Not WinActive("PRODUCTS SYST","") Then WinActivate("PRODUCTS SYST","")

WinWaitActive("PRODUCTS SYST","")

Send("{F3}")

WinWait("Select Task by Code","")

If Not WinActive("Select Task by Code","") Then WinActivate("Select Task by Code","")

WinWaitActive("Select Task by Code","")

Send("tv{ENTER}")

WinWait("(MGB)","")

If Not WinActive("(MGB)","") Then WinActivate("Open Service Activity","")

WinWaitActive("(MGB)","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}duse65{TAB}duse65") ************************ this is where col1 row1 goes

send("{alt}")

Send("f")

WinWait("", "", 200)

Send("r")

WinWait("", "", 200)

Send("{TAB}{TAB}{TAB}{TAB}{SPACE}{TAB}TV_output{TAB}{TAB}{SPACE}")

WinWait("", "", 1000)

send("{alt}")

Send("f")

WinWait("", "", 200)

Send("x")

WinWait("", "", 2000)

#Include<file.au3>

#include <INet.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$s_SmtpServer = "localhost" ; address for the smtp-server to use - REQUIRED

$s_FromName = "AutoIt" ; name from who the email was sent

$s_FromAddress = "autoit@mgbp.com" ; address from where the mail should come

$s_ToAddress = "USER@SERVER.com" ; destination address of the email - REQUIRED ***************************************************** col2 row1

$s_Subject = "CURRENT SERVICE CALLS" ; subject from the email - can be anything you want it to be

$as_Body = "This Is A Test" ; the messagebody from the mail - can be left blank but then you get a blank mail

$s_AttachFiles = "o:\TV_output.txt" ; the file you want to attach- leave blank if not needed

$s_CcAddress = "" ; address for cc - leave blank if not needed

$s_BccAddress = "" ; address for bcc - leave blank if not needed

$s_Username = "" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)

$s_Password = "" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)

$IPPort = 25 ; port used for sending the mail

$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS

;~ $IPPort=465 ; GMAIL port used for sending the mail

;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

Global $oMyRet[2]

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)

If @error Then

MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)

EndIf

;

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)

$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])

If FileExists($S_Files2Attach[$x]) Then

$objEmail.AddAttachment ($S_Files2Attach[$x])

Else

$i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]

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

$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

; Sent the Message

$objEmail.Send

if @error then

SetError(2)

return $oMyRet[1]

EndIf

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

then repeat

Link to comment
Share on other sites

***** NOT TESTED

#include <file.au3>
#include <INet.au3>

; Variables
;##################################
$s_SmtpServer = "MailServer"               ; address for the smtp-server to use - REQUIRED
$s_FromName = "Name"                       ; name from who the email was sent
$s_FromAddress = "your@Email.Address.com"  ;  address from where the mail should come
$s_ToAddress = "THIS IS SET LATER!!!  "    ; destination address of the email - REQUIRED
$s_Subject = "Userinfo"                    ; subject from the email - can be anything you want it to be
$as_Body = ""                             ; the messagebody from the mail - can be left blank but then you get a blank mail
$s_AttachFiles = ""                       ; the file you want to attach- leave blank if not needed
$s_CcAddress = "CCadress1@test.com"        ; address for cc - leave blank if not needed
$s_BccAddress = "BCCadress1@test.com"      ; address for bcc - leave blank if not needed
$s_Username = "******"                     ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$s_Password = "********"                   ; password for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$IPPort = 25                              ; port used for sending the mail
$ssl = 0                                  ; enables/disables secure socket layer sending - put to 1 if using httpS
;~ $IPPort=465                            ; GMAIL port used for sending the mail
;~ $ssl=1                                 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################

Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $Records
Global $File = @ScriptDir & "\" 

If Not _FileReadToArray($File, $Records) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

For $x = 1 To $Records[0]
    $Split = StringSplit($Records[$x], ",")

    If $Split[0] <> 3 Then
        MsgBox(4096, "Error", " Incorrect information on line #" & $x)
        Exit
    EndIf
    
    Dim $User_ID = $Split[1]
    Dim $User_Name = $Split[2]
    Dim $User_Email = $Split[3]
    
    $ret = _Tv_Input($User_ID, $User_Name)
    If @error Then
        MsgBox(4096, "Error sending message", "Error code:" & @error & "  Retrun:" & $ret)
        Exit
    EndIf
    
    Sleep(2000)
    
    $s_ToAddress = $User_Email ;???
    ; any other mail changes here
    
    $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
        MsgBox(4096, "Error sending message", "Error code:" & @error & "  Rc:" & $rc)
        Exit
    EndIf
    
Next

MsgBox(4096, "GREAT!!!!", " The Program worked, Thanks    ....Valuater   ", 5 )
Exit

; TV FUNCTIONS -------------------------------------


Func _Tv_Input(ByRef $User_ID, ByRef $User_Name)

    DriveMapAdd("o:", "\\server\u\")
    FileDelete("o:\TV_output.txt")


    Run("driver.exe")
    WinWait("Information System", "Enter your User ID a")
    Send("******{TAB}******")
    Send("{ENTER}")
    WinWait("About INFORMATIO", "BUS P")
    Send(@TAB)
    Send("{ENTER}")

    WinWait("PRODUCTS SYST", "")
    If Not WinActive("PRODUCTS SYST", "") Then WinActivate("PRODUCTS SYST", "")
    WinWaitActive("PRODUCTS SYST", "")
    Send("{F3}")
    WinWait("Select Task by Code", "")
    If Not WinActive("Select Task by Code", "") Then WinActivate("Select Task by Code", "")
    WinWaitActive("Select Task by Code", "")
    Send("tv{ENTER}")
    WinWait("(MGB)", "")
    If Not WinActive("(MGB)", "") Then WinActivate("Open Service Activity", "")
    WinWaitActive("(MGB)", "")
    Send("{TAB 9}") 
    Send($User_ID)
    Send("{TAB}") ;************************ this is where col1 row1 goes
    Send("{alt}")
    Send("f")
    WinWait("", "", 200)
    Send("r")
    WinWait("", "", 200)
    Send("{TAB 4}{SPACE}{TAB}TV_output{TAB 2}{SPACE}")

    WinWait("", "", 1000)
    Send("{alt}")
    Send("f")
    WinWait("", "", 200)
    Send("x")
     If @error Then Return SetError(1)
EndFunc   ;==>_Tv_Input


; EMAIL FUNCTIONS --------------------------------------


Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    $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])
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                $i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
                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
    $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
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
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

8)

NEWHeader1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...