Jump to content

Cyborg5000

Active Members
  • Posts

    118
  • Joined

  • Last visited

Recent Profile Visitors

407 profile views

Cyborg5000's Achievements

Adventurer

Adventurer (3/7)

0

Reputation

  1. @ioa747 Thanks a lot, was able to set it to a loop on the text file.
  2. a small help? how can i use it in a loop of 1000 text files?
  3. Thanks, but text may be available between Vendor Ticket: and Notification in further instances.
  4. Iam trying to capture an empty space/ string between two texts, but also want to add text to it. Reason for Impact: NA Recovery Action: NA Start Time (CST): 07-Mar-2023 02:02 AM End Time (CST): NA Vendor Ticket: Notification: So between Vendor Ticket: and Notification if empty add NA
  5. Unsure what iam doing wrong here, but iam getting data appended to a cell each time a blank data is received in _stringbetween. Although i have tried if @error then and different methods to write to the colloumn as N/A. #include <Excel.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <String.au3> Global $sWorkbookPath = "C:\example.xlsx" ; Replace with your workbook path Global $sWorksheetName = "Sheet1" ; Replace with your worksheet name Global $xlUp = -4162 Global $sFolder = "D:\Test" Global $oExcel = _Excel_Open() ; Open an instance of Excel Global $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbookPath) ; Open the workbook Global $GNCNAME = "GNC-NAME:" Global $SGE = "SGE:" Global $UGE = "UGE:" Global $ElapsedTime = "Elapsed Time:" Global $OutageDuration = "Outage Duration:" Global $ImpactDuration = "Impact Duration:" Global $ImpactSummary = "Impact Summary:" Global $AffectedCI = "Affected CI:" Global $UpdateCST = "Update(CST):" Global $ReasonforImpact = "Reason for Impact:" Global $RecoveryAction = "Recovery Action:" Global $StartTimeCST = "Start Time (CST):" Global $EndTimeCST = "End Time (CST):" Global $VendorTicket = "Vendor Ticket:" Global $Notification = "Notification:" Global $Resources = "Resources:" Global $GNCCONTACT = "GNC-CONTACT:" Local $hSearch = FileFindFirstFile($sFolder & "\" & "*.txt") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") ;Return False EndIf ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; Display the file name. ;$iResult = MsgBox(($MB_OKCANCEL + $MB_SYSTEMMODAL), "", "File: " & $sFileName) ;If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button. ;MsgBox(0, "test", $sFolder & "\" & $sFileName) $tempfolder = "D:\temp" FileCopy($sFolder & "\" & $sFileName, $tempfolder & "\test.txt") Global $tempfolder = "D:\Temp" Local $aFiles = _FileListToArray($tempfolder, "*.txt", $FLTA_FILES) For $i = 0 To UBound($aFiles) - 1 Local $sFilePath = $tempfolder & "\" & $aFiles[$i] Global $sFileContents = FileRead($sFilePath) FileDelete("D:\Temp\String.txt") Call("GNC_NAME_SGE", $sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) Call("GNC_NAME_UGE", $sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) Call("SGE_OutageDuration", $sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) Call("Resources_GNCCONTACT", $sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) Sleep(1900) Next FileDelete($tempfolder & "\test.txt") FileDelete("D:\Temp\String.txt") WEnd _Excel_BookSave($oWorkbook) ; Save the workbook _Excel_Close($oExcel) ; Close the Excel instance Func GNC_NAME_SGE($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ GNC NAME - SGE ;If StringInStr($sFileContents, $GNCNAME) And StringInStr($sFileContents, $SGE) Then Local $aMatches = _StringBetween($sFileContents, $GNCNAME, $SGE) If IsArray($aMatches) Then ; String was found between the start and end strings Local $sMatch = $aMatches[0] Sleep(100) $filestring = ("D:\Temp\String.txt") FileWrite($filestring, $sMatch) Local $sFileContents1 = FileRead($filestring) Do Local $sNewContents = StringStripWS($sFileContents1, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) Until @extended = 0 FileDelete($filestring) FileWrite($filestring, $sNewContents) $line1 = FileReadLine($filestring, 1) $line2 = FileReadLine($filestring, 2) $line3 = FileReadLine($filestring, 3) ;MsgBox(0, "zvzxc", $line1) Local $sColumnName = "B" ; Replace with your column name Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, "A").Value = "SGE" ;$oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch $oWorksheet.Cells($iLastRow + 1, "R").Value = $sFilePath $oWorksheet.Cells($iLastRow + 1, "B").Value = $line1 $oWorksheet.Cells($iLastRow + 1, "C").Value = $line2 $oWorksheet.Cells($iLastRow + 1, "D").Value = $line3 Sleep(100) FileDelete("D:\Temp\String.txt") EndIf EndFunc ;==>GNC_NAME_SGE Func GNC_NAME_UGE($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ GNC NAME - UGE Local $aMatches = _StringBetween($sFileContents, $GNCNAME, $UGE) If IsArray($aMatches) Then ; String was found between the start and end strings ; String was found between the start and end strings Local $sMatch = $aMatches[0] Sleep(100) $filestring = ("D:\Temp\String.txt") FileWrite($filestring, $sMatch) Local $sFileContents1 = FileRead($filestring) Do Local $sNewContents = StringStripWS($sFileContents1, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) Until @extended = 0 FileDelete($filestring) FileWrite($filestring, $sNewContents) $line1 = FileReadLine($filestring, 1) $line2 = FileReadLine($filestring, 2) $line3 = FileReadLine($filestring, 3) ;MsgBox(0, "zvzxc", $line1) Local $sColumnName = "B" ; Replace with your column name Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, "A").Value = "UGE" ;$oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch ; Add the new data to the next row in the column $oWorksheet.Cells($iLastRow + 1, "R").Value = $sFilePath $oWorksheet.Cells($iLastRow + 1, "B").Value = $line1 $oWorksheet.Cells($iLastRow + 1, "C").Value = $line2 $oWorksheet.Cells($iLastRow + 1, "D").Value = $line3 Sleep(100) FileDelete("D:\Temp\String.txt") EndIf EndFunc ;==>GNC_NAME_UGE Func SGE_OutageDuration($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ SGE - OutageDuration Local $aMatches = _StringBetween($sFileContents, $SGE, $OutageDuration) If IsArray($aMatches) Then ; String was found between the start and end strings Local $sMatch = $aMatches[0] Local $sColumnName = "E" ; Replace with your column name Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch ; Add the new data to the next row in the column $oWorksheet.Cells($iLastRow + 1, "F").Value = "Outage Duration:" ;Sleep(5000) EndIf EndFunc ;==>SGE_OutageDuration Func Resources_GNCCONTACT($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ Resources - GNCCONTACT Local $aMatches = _StringBetween($sFileContents, $Resources, $GNCCONTACT) If IsArray($aMatches) Then ; String was found between the start and end strings Local $sMatch = $aMatches[0] Local $sColumnName = "Q" ; ;Replace with your column name Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch ; Add the new data to the next row in the column ;Sleep(5000) EndIf EndFunc ;==>Resources_GNCCONTACT In below function or text "$Resources and $GNCCONTACT" there is sometimes a blank text and iam trying to write NA to "$oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch" Func Resources_GNCCONTACT($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ Resources - GNCCONTACT Local $aMatches = _StringBetween($sFileContents, $Resources, $GNCCONTACT) If IsArray($aMatches) Then ; String was found between the start and end strings Local $sMatch = $aMatches[0] Local $sColumnName = "Q" Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch ; Add the new data to the next row in the column ;Sleep(5000) EndIf tried as below Func Resources_GNCCONTACT($sFileContents, $sWorkbookPath, $sWorksheetName, $oExcel, $oWorkbook) ;================================================================ Resources - GNCCONTACT Local $aMatches = _StringBetween($sFileContents, $Resources, $GNCCONTACT) If @Error Then Local $sColumnName = "Q" Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = "NA"; Add the new data to the next row in the column else Local $sColumnName = "Q" Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $aMatches ; Add the new data to the next row in the column ;Sleep(5000) EndIf EndFunc ;==>Resources_GNCCONTACT
  6. Global $sWorkbookPath = "C:\example.xlsx" ; Replace with your workbook path Global $sWorksheetName = "Sheet1" ; Replace with your worksheet name Global $xlUp = -4162 Global $sFolder = "D:\test" Global $oExcel = _Excel_Open() ; Open an instance of Excel Global $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbookPath) ; Open the workbook ;Call("NOC_SGE") Call("SGE_Impact_duration") ;Call("SGE_Outage_duration") ;Call("NOC_UGE") ;Call("UGE_Impact_duration") ;Call("UGE_Outage_duration") ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;================================================================Text having SGE_Outage_duration Func SGE_Impact_duration() Local $sStartString = "SGE:" Local $sEndString = "Impact Duration:" ; Get a list of all text files in the folder Local $aFiles = _FileListToArray($sFolder, "*.txt", $FLTA_FILES) ; Check if any files were found If @error Then MsgBox($MB_OK, "Error", "No text files found in folder.") Exit EndIf ; Loop through each text file and search for the string between the start and end strings For $i = 1 To $aFiles[0] Global $sFilePath = $sFolder & "\" & $aFiles[$i] Global $sFileContents = FileRead($sFilePath) If @error Then MsgBox($MB_OK, "Error", "Error reading file: " & $sFilePath) Else Global $aMatches = StringRegExp($sFileContents, "(?s)" & $sStartString & "(.*?)" & $sEndString, 4) If IsArray($aMatches) Then ; String was found between the start and end strings Global $sMatch = $aMatches[0] ;MsgBox (0, "test", $sMatch) Call("SGE_ID_Entry") EndIf EndIf Next EndFunc ;==>NOC_SGE_Outage_duration Func SGE_ID_Entry() Local $sColumnName = "C" ; Replace with your column name Local $oWorksheet = $oWorkbook.Sheets($sWorksheetName) ; Select the worksheet Local $iLastRow = $oWorksheet.Range($sColumnName & $oWorksheet.Rows.Count).End($xlUp).Row ; Find the last row in the column $oWorksheet.Cells($iLastRow + 1, $sColumnName).Value = $sMatch ; Add the new data to the next row in the column $oWorksheet.Cells($iLastRow + 1, "A").Value = "SGE" $oWorksheet.Cells($iLastRow + 1, "D").Value = $sFilePath ;_Excel_RangeWrite($oWorkbook, Default, $aMatches[$i], "A2" & $iRow) _Excel_BookSave($oWorkbook) ; Save the workbook _Excel_Close($oExcel) ; Close the Excel instance EndFunc ;==>NOC_SGE_OD_Entry ;=============================================================================>NOC_SGE_OD_Entry Iam using the above code, however iam unable to read the files 1 by 1 in a numerical form starting from 1 - 100 + My array looks default as below. I have tried using _ArraySort($avArray, 0, 0, 0, 1) _FileListToArrayRec Need to sort arry or read files 1, 2, 3,4 ,5 .......and so on Any help appreciated
  7. As a basic try this Func DownloadPDFFile($fileURL, $downloadPath) ; Start the WebDriver session Local $sDriverPath = "C:\webdriver\chromedriver.exe" ; replace with your webdriver path _WD_Startup() Local $sSession = _WD_CreateSession("chrome", $WD_FLAG_LOCAL) ; Navigate to the file download URL _WD_Navigate($sSession, $fileURL) ; Wait for the file to download Local $bDownloaded = False Local $iTimeout = 30 While $iTimeout > 0 And Not $bDownloaded Sleep(1000) $iTimeout -= 1 If _FileCountLines($downloadPath & "\filename.pdf") > 0 Then $bDownloaded = True EndIf WEnd ; Quit the WebDriver session _WD_Close($sSession) _WD_Shutdown() ; Return the downloaded file path Return $downloadPath & "\filename.pdf" EndFunc
  8. Hello i need a pointer for this piece of code. Local $sHost = "vw-aus-domdv999" ; FileRead("Test.txt") ; prefix can be anything IncrementHostName($sHost) ConsoleWrite($sHost & @CRLF) ; FileWrite("Test2.txt", $sHost) Func IncrementHostName(ByRef $sName) Local $vLast = StringRight($sName, 3) Local $vFirst = StringLeft($vLast, 1) $vLast = Number(StringRight($vLast, 2)) + 1 If $vLast > 99 Then $vLast = 1 $vFirst = Chr(Asc($vFirst) + 1) If $vFirst = ":" Then $vFirst = "a" ; change to letter If $vFirst = "{" Then $vFirst = "0" ; start all over again EndIf $sName = StringTrimRight($sName, 3) & $vFirst & StringFormat("%02i", $vLast) EndFunc ;==>IncrementHostName The host names generates just fine with the above code, however if the host name has vw-aus-domdv099, it skips -domdv100 and so on at each generation. another example is if the host name is vl-pun-domqa599 it will skip vl-pun-domqa600 and directly give vl-pun-domqa601 and so on.... i tried adding and modifiying some combinations, but nothing has changed so far.....
  9. that's what iam trying to get help about... unsure where or how to use your code with mine as posted...
  10. Hello @Nine and @jchd Very much thanks for replaying back and giving some instights... Appreciate your help. below is my code adapted and working.. ;Copy any of these to clipboard xxx xxxx111 , xxx11 , xxxx-xxxx-1 , xx4x11 Global $sOldContents $File = "C:\test.txt" $Open = FileOpen($File, 0) $Read = FileRead($Open) ClipPut($Read) Local $counter = 0 Local $sCbContents = ClipGet() While $counter <= 5 If $sOldContents <> $sCbContents And StringRegExp($sCbContents, "(.*?)(\d)$") Then $sCbContents = StringReplace($sCbContents, "'", "#SingleQts#") $sCbContents = StringReplace($sCbContents, '"', "#DbleQts#") $sCbContents = Execute(StringRegExpReplace($sCbContents, "(.*?)(\d+)$", '"$1" & Number("$2") +1')) If @error Then $sCbContents = StringReplace($sCbContents, "#SingleQts#", "'") $sCbContents = StringReplace($sCbContents, "#DbleQts#", '"') $sOldContents = $sCbContents EndIf EndIf $counter = $counter + 1 FileWrite("C:\test2.txt", StringRegExpReplace($sCbContents, "(\+|=|!|#|\^|\{|\})", "{\1}") & @CRLF) WEnd FileClose($Open) C:\test.txt file is the file into which the last hostname that was used is gathered via powercli by quering the VC. Please note " Local $sPrefix = "vw-aus-domdv" ; is not static.... (The start of the VM's host names may start with vw-aus-domdv001 / vw-aus-domqa001 (vw-aus-domdv/qa are not static and neither their start) vw-tlv-istqa/vw-aus-istdv, vw-pun-istdv are taken/made as per users location and BU. My main concern is to use the above code and use if for further generating the hosts with alphabets capturing only the last 3 letters/numbers, once the host name reaches till domqa999/domdv999/domsp999, istqa999, istdv999, istsp999 (istsp/domqa/domdv are not static)
  11. Hi, I had previously posted a thread for help, for which i had a great help from the moderators, and appreciate very much for their concerns and pointers. However now i have another set of pointers/help to get with the same. Now this time it isnt a number but alphabets. My enviroment is exhausting hostnames and will further need to drill down and start with alphabets. Basically 1st with the help of WEBDRIVER UDF iam reading a user submitted form ,2 Further with the details captured iam going to the VC, with powercli iam searching for the last host name used as per the user's Business unit's (PLPF (Productline & Productfamily) (The start of the VM's host names may start with vw-aus-domdv001 / vw-aus-domqa001 (vw-aus-domdv/qa are not static) Once i have the last hostname used, with a small code iam generating the further list of hostnames that can be used. ;-------------------------------------------------- The issue/challenge is, that in some VC's and BU's iam getting over with vw-aus-domdv999 and need to further use alphabets Example: if the last hostname was used as vw-aus-domdv999 i will have to start using vw-aus-domdva01 vw-aus-domdva02 and so on....till vw-aus-domdva90 then vw-aus-domdvb01 vw-aus-domdvb02
  12. @Nine and @mLipok Thanks to both of you for your help and directives... was able to achieve mixing your code and below code...🙏✌️
×
×
  • Create New...