Search the Community
Showing results for tags 'Script included'.
-
Hi all, I have this script, inside my program, that : a) take a source file (.csv) (around 5.000 lines), internal.csv b ) converts it so that I can separate each single part (sometimes the first item is i.e. '"Legend of, Zelda",PC,..'. so that there is an extra "," to consider) b1) "Normalizes" the names found so that they can be compared to a .xml structure c) create a string for every line in .xml format (<z:row c0='aaaaa' It2='UZ' Avail='No' fold='E...) d) checks the string with another "arrayed" file (50.000 lines), $mydb e) if _arraysearch returns OK then add to an array the complete string (all the parts of b ) and 2 fields of the .xml, c7=... and c8=...) f) creates a file and uploads it to a server with the code shown below it takes aroud 15 mins to finish. Is there a way to optimize the code to reduce this time? Thanks, Marco P.s. The code works, so no problem if some var/const is missing, probably they have been called by the main .au3 that has all the include needed. #include <FTPEx.au3> $exportfile = @ScriptDir & "\DB\internal.csv" Dim $array2db[1] Dim $mydb Global $file2ftp = @TempDir & "\temp2db.txt" Func _exp2db($user) Local $user2db Dim $csv_list[1][8] Dim $csv_array If $user= "" Then $user2db = "Test_User" Else $user2db = $user EndIf _status(0, "Converting now .csv") _FileReadToArray($exportfile, $csv_array) For $i = 2 To UBound($csv_array) - 1 If StringInStr($csv_array[$i], ", ,") Then $string = StringReplace($csv_array[$i], ", ,", ",@,", 1) Else $string = $csv_array[$i] EndIf If StringInStr($string, ", ") Then $string = StringReplace($string, ", ", "^", 1) $name_s = _StringBetween($string, "", ",") $name = _cleanfordb($name_s[0]) ;name cleaned (remove " and ^ I used before and replace , if exists) $string = StringReplace($string, ",", "*", 1) ; comma to get the next item $string = StringReplace($string, ",", "#", 1) ; comma to get the next item $item2 = _StringBetween($string, "*", "#") ;another item $item3 = _StringBetween($string, "#", ",") ;another item $string = StringReplace($string, ",", "_", 1) ; comma to get the next item $item4 = _StringBetween($string, "_", ",") ;another item $item5 = _StringBetween($string, ",", ",") ;another item If $item4[0] <> "TRASH" And $item4[0] <> "PC" And $item4[0] <> "PSX" And $item4[0] <> "WII" And $item4[0] <> "DS" Then $item5[0] = "TRASH" ; $item4[0] = "X" EndIf If $item4[0] = "TRASH" Then $item5[0] = $item4[0] $item4[0] = "None" EndIf $item6= StringRight($string, 2) ;another item If $item6= "es" Then $item6= "Yes" ReDim $csv_list[$i + 1][8] $csv_list[$i][0] = $name $csv_list[$i][1] = $item4[0] If $item5[0] <> "@" Then $csv_list[$i][2] = $item5[0] $csv_list[$i][3] = $item6 $csv_list[$i][4] = $item2[0] $csv_list[$i][5] = $item3[0] _FileReadToArray($originalDB, $mydb) $string = "<z:row c0='" & _normalize_db($csv_list[$i][0]) & "' c1='" & $csv_list[$i][2] & "' c2='" & $csv_list[$i][3] & "' c3='" & $csv_list[$i][1] [b]$check= _ArraySearch($mydb, $string, 39, UBound($mydb), 0, 1)[/b] if $check <> -1 Then $csv_list[$i][6] = _find1($check_1) $csv_list[$i][7] = _find2($check_1) EndIf $string2db = $user2db & "|" & $csv_list[$i][0] & "|" & $csv_list[$i][1] & "|" & $csv_list[$i][2] & "|" & $csv_list[$i][3] & "|" & $csv_list[$i][4] & "|" & $csv_list[$i][5] & "|" & $csv_list[$i][6] & "|" & $csv_list[$i][7] _ArrayAdd($array2db, $string2db) Next _FileWriteFromArray($file2ftp, $array2db) _status(0, "Uploading now") _upload2server($user2db) EndFunc ;==>_exp2db Func _cleanfordb($a) If StringInStr($a, "^") Then $a= StringReplace($a, "^", ", ") ; ^ If StringInStr($a, '"') Then $a= StringMid($a, 2, StringLen($a) - 2) Return $a EndFunc ;==>_cleanfordb Func _upload2server($us) Local $server = "myserver.com" Local $username = "mylogin" Local $password = "mypw" $i_Passive = '1' $port = '21' $open = _FTP_Open("MyFTP") $connect = _FTP_Connect($open, $server, $username, $password, $i_Passive, $port) If $connect = 0 Then _status(1, "Unable to connect") Else $send = _FTP_FilePut($connect, $file2ftp, "/in/" & $us & "_db.txt") If $send = 0 Then _status(1, "Error in uploading file") Else _status(0, "Updated") EndIf EndIf $close = _FTP_Close($open) ; FileDelete($file2ftp) EndFunc ;==>_upload2server and Func _normalize_db($name) If StringInStr($name, "&") Then $name= StringReplace($name, "&", "&") ; & If StringInStr($name, "'") Then $name= StringReplace($name, "'", "'") ; ' If StringInStr($name, '"') Then $name= StringReplace($name, '"', """) ; " Return $name EndFunc ;==>_normalize_db Func _find1($cc) $p = _StringBetween($mydb[$cc], "c4='", "'") If $p[0] = 0 Then $p = _StringBetween($mydb[$cc], "c5='", "'") Return $p[0] EndFunc ;==> _find1 Func _find2($cc) $p = _StringBetween($mydb[$cc], "c6='", "'") If $p[0] = 0 Then $p = _StringBetween($mydb[$cc], "c7='", "'") Return $p[0] EndFunc ;==>_find2