Jump to content

I want to save download links with spesific languages among a lot of other languages


Go to solution Solved by Nine,

Recommended Posts

Posted (edited)

Please i want to correct my code to be able to save spesific languages in download links without repetition and in a correct easy way

here is my code :

#NoTrayIcon
#include <Array.au3>

Global $aGoodLatestx64

$x64SAPValue = "301"
$aTarget = "sap-x64-301.exe|sap-x64-301ar.exe|sap-x64-301am.exe|sap-x64-301az.exe|sap-x64-301bg.exe|sap-x64-301ca.exe|sap-x64-301sc.exe|sap-x64-301tc.exe|sap-x64-301cro.exe|sap-x64-301cz.exe|sap-x64-301dk.exe|sap-x64-301nl.exe|sap-x64-301eu.exe|sap-x64-301fi.exe|sap-x64-301fr.exe|sap-x64-301gl.exe|sap-x64-301d.exe|sap-x64-301el.exe|sap-x64-301he.exe|sap-x64-301hu.exe|sap-x64-301id.exe|sap-x64-301it.exe|sap-x64-301jp.exe|sap-x64-301kr.exe|sap-x64-301lt.exe|sap-x64-301mn.exe|sap-x64-301no.exe|sap-x64-301pl.exe|sap-x64-301pt.exe|sap-x64-301br.exe|sap-x64-301ro.exe|sap-x64-301ru.exe|sap-x64-301srbcyr.exe|sap-x64-301sk.exe|sap-x64-301slv.exe|sap-x64-301es.exe|sap-x64-301sw.exe|sap-x64-301th.exe|sap-x64-301tr.exe|sap-x64-301uk.exe|sap-x64-301vn.exe"
$afiles = StringSplit($aTarget, "|", 2)
For $i = 0 To UBound($afiles) - 1
    $aSAPLocals = "ar|en|fr|d|ru|es|it|tr" ; >>> I want to Save links with those Languages only without repitition and accurately
    $Langfiles = StringSplit($aSAPLocals, "|", 2)
    For $ix = 0 To UBound($Langfiles) - 1
        $aSAPLngs = $Langfiles[$ix]
        If StringInStr($afiles[$i], $aSAPLngs) Then
            $aGoodLatestx64 &= 'https://www.sap.com/sap/SAP-' & $x64SAPValue & $aSAPLngs & '.exe' & @CRLF
        EndIf
    Next
Next

Local $hFileOpen = FileOpen(@ScriptDir & '\Down_Links.txt', 2)
FileWrite($hFileOpen, "SAP x64" & @CRLF)
FileWrite($hFileOpen, $aGoodLatestx64)
FileClose($hFileOpen)

 

Problems :

1- my code save links with spesific languages but there is repetion

2- my code didn't save the first one >>> sap-x64-301.exe which represent the english languages (there is no letter en to represent english ... only empty before .exe)

 

Requirements :

1- correction to save all links in spesific languages only without repitition

2- save the english one if could be

 

Thanks in advance to all contributers and big masters

Edited by Davidyese
Posted (edited)

Hi @Davidyese 👋 ,

the following is definitely not my best code, but I did not want to change your approach too much.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y

#include-once
#include <Array.au3>

_Main()

Func _Main()
    Local Const $sSAPLocals = "ar|en|fr|d|ru|es|it|tr"
    Local Const $aLangfiles = StringSplit($sSAPLocals, "|", 2)

    Local Const $sTarget    = "sap-x64-301.exe|sap-x64-301ar.exe|sap-x64-301am.exe|sap-x64-301az.exe|sap-x64-301bg.exe|sap-x64-301ca.exe|sap-x64-301sc.exe|sap-x64-301tc.exe|sap-x64-301cro.exe|sap-x64-301cz.exe|sap-x64-301dk.exe|sap-x64-301nl.exe|sap-x64-301eu.exe|sap-x64-301fi.exe|sap-x64-301fr.exe|sap-x64-301gl.exe|sap-x64-301d.exe|sap-x64-301el.exe|sap-x64-301he.exe|sap-x64-301hu.exe|sap-x64-301id.exe|sap-x64-301it.exe|sap-x64-301jp.exe|sap-x64-301kr.exe|sap-x64-301lt.exe|sap-x64-301mn.exe|sap-x64-301no.exe|sap-x64-301pl.exe|sap-x64-301pt.exe|sap-x64-301br.exe|sap-x64-301ro.exe|sap-x64-301ru.exe|sap-x64-301srbcyr.exe|sap-x64-301sk.exe|sap-x64-301slv.exe|sap-x64-301es.exe|sap-x64-301sw.exe|sap-x64-301th.exe|sap-x64-301tr.exe|sap-x64-301uk.exe|sap-x64-301vn.exe"
    Local Const $aFiles     = StringSplit($sTarget, "|", 2)

    Local Const $sX64SAPValue = "301"

    Local $sSAPLngs
    Local $sGoodLatestx64

    For $i = 0 To UBound($aFiles) - 1
        For $ix = 0 To UBound($aLangfiles) - 1
            $sSAPLngs = $aLangfiles[$ix]
            If StringInStr($aFiles[$i], $sX64SAPValue & '.exe') Then
                $sGoodLatestx64 &= 'https://www.sap.com/sap/SAP-' & $sX64SAPValue & '.exe' & @CRLF
            EndIf
            If StringInStr($aFiles[$i], $sSAPLngs & '.exe') Then
                $sGoodLatestx64 &= 'https://www.sap.com/sap/SAP-' & $sX64SAPValue & $sSAPLngs & '.exe' & @CRLF
            EndIf
        Next
    Next

    Local $sGoodLatestx64WithoutLastCRLF = StringTrimRight($sGoodLatestx64, 2)

    Local Const $aGoodLatestX64 = StringSplit($sGoodLatestx64WithoutLastCRLF, @CRLF, BitOr(1, 2))

    Local $aUniqueList = _ArrayUnique($aGoodLatestX64)
    _ArraySort($aUniqueList)
    _ArrayDelete($aUniqueList, 0)

    $sGoodLatestx64 = _ArrayToString($aUniqueList, @CRLF)
    _WriteFile($sGoodLatestx64)

EndFunc

Func _WriteFile($sData)
    Local $hFileOpen = FileOpen(@ScriptDir & '\Down_Links.txt', 2)
    FileWrite($hFileOpen, "SAP x64" & @CRLF)
    FileWrite($hFileOpen, $sData)
    FileClose($hFileOpen)
EndFunc

Output:

SAP x64
https://www.sap.com/sap/SAP-301.exe
https://www.sap.com/sap/SAP-301ar.exe
https://www.sap.com/sap/SAP-301d.exe
https://www.sap.com/sap/SAP-301es.exe
https://www.sap.com/sap/SAP-301fr.exe
https://www.sap.com/sap/SAP-301it.exe
https://www.sap.com/sap/SAP-301ru.exe
https://www.sap.com/sap/SAP-301tr.exe

In case you want to avoid the long unreadable files string:

Spoiler
Local Const $aFiles[] = _
    [ _
        'sap-x64-301.exe', _
        'sap-x64-301am.exe', _
        'sap-x64-301ar.exe', _
        'sap-x64-301az.exe', _
        'sap-x64-301bg.exe', _
        'sap-x64-301br.exe', _
        'sap-x64-301ca.exe', _
        'sap-x64-301cro.exe', _
        'sap-x64-301cz.exe', _
        'sap-x64-301d.exe', _
        'sap-x64-301dk.exe', _
        'sap-x64-301el.exe', _
        'sap-x64-301es.exe', _
        'sap-x64-301eu.exe', _
        'sap-x64-301fi.exe', _
        'sap-x64-301fr.exe', _
        'sap-x64-301gl.exe', _
        'sap-x64-301he.exe', _
        'sap-x64-301hu.exe', _
        'sap-x64-301id.exe', _
        'sap-x64-301it.exe', _
        'sap-x64-301jp.exe', _
        'sap-x64-301kr.exe', _
        'sap-x64-301lt.exe', _
        'sap-x64-301mn.exe', _
        'sap-x64-301nl.exe', _
        'sap-x64-301no.exe', _
        'sap-x64-301pl.exe', _
        'sap-x64-301pt.exe', _
        'sap-x64-301ro.exe', _
        'sap-x64-301ru.exe', _
        'sap-x64-301sc.exe', _
        'sap-x64-301sk.exe', _
        'sap-x64-301slv.exe', _
        'sap-x64-301srbcyr.exe', _
        'sap-x64-301sw.exe', _
        'sap-x64-301tc.exe', _
        'sap-x64-301th.exe', _
        'sap-x64-301tr.exe', _
        'sap-x64-301uk.exe', _
        'sap-x64-301vn.exe' _
    ]

 

It works, but it's not very flexible and also without error handling. If it's still okay for your goal, fine 🤝 .

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

  • Solution
Posted (edited)

Here my take with SRE :

#include <Array.au3>
#include <Constants.au3>

Local $sTarget = "sap-x64-301.exe|sap-x64-301ar.exe|sap-x64-301am.exe|sap-x64-301az.exe|sap-x64-301bg.exe|sap-x64-301ca.exe|sap-x64-301sc.exe|sap-x64-301tc.exe|sap-x64-301cro.exe|sap-x64-301cz.exe|sap-x64-301dk.exe|sap-x64-301nl.exe|sap-x64-301eu.exe|sap-x64-301fi.exe|sap-x64-301fr.exe|sap-x64-301gl.exe|sap-x64-301d.exe|sap-x64-301el.exe|sap-x64-301he.exe|sap-x64-301hu.exe|sap-x64-301id.exe|sap-x64-301it.exe|sap-x64-301jp.exe|sap-x64-301kr.exe|sap-x64-301lt.exe|sap-x64-301mn.exe|sap-x64-301no.exe|sap-x64-301pl.exe|sap-x64-301pt.exe|sap-x64-301br.exe|sap-x64-301ro.exe|sap-x64-301ru.exe|sap-x64-301srbcyr.exe|sap-x64-301sk.exe|sap-x64-301slv.exe|sap-x64-301es.exe|sap-x64-301sw.exe|sap-x64-301th.exe|sap-x64-301tr.exe|sap-x64-301uk.exe|sap-x64-301vn.exe"

Local $aList = StringRegExp($sTarget, "sap-x64-301(?||ar|en|fr|d|ru|es|it|tr)\.exe", $STR_REGEXPARRAYGLOBALMATCH)
$aList = _ArrayUnique($aList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)
Local $hFile = FileOpen("Down_Links.txt", $FO_OVERWRITE)
FileWriteLine($hFile, "SAP x64")
For $sLink In $aList
  FileWriteLine($hFile, "https://www.sap.com/sap/" & $sLink)
Next
FileClose($hFile)

I get also EN link.

SAP x64
https://www.sap.com/sap/sap-x64-301.exe
https://www.sap.com/sap/sap-x64-301ar.exe
https://www.sap.com/sap/sap-x64-301fr.exe
https://www.sap.com/sap/sap-x64-301d.exe
https://www.sap.com/sap/sap-x64-301it.exe
https://www.sap.com/sap/sap-x64-301ru.exe
https://www.sap.com/sap/sap-x64-301es.exe
https://www.sap.com/sap/sap-x64-301tr.exe

 

Edited by Nine
better code
Posted
18 minutes ago, Nine said:

I get also EN link.

Thanks @Nine, I missed that one. I like your approach - it's basically the one I also had chosen.
One little thing: Your URLs are not named like Davidyese want it to.

@Davidyese: I adjusted my "solution". But let us know, are the created URLs valid?
https://www.sap.com/sap/SAP-301fr.exe ==> can only be downloaded when you're signed in, right?

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

No, I mean this difference @Nine:

My link:    https://www.sap.com/sap/SAP-301fr.exe
Your linK:  https://www.sap.com/sap/sap-x64-301fr.exe

I cannot test any of these, because I am not logged in (I will not create an account).
I believe your link should be the right one, but the OP created the link differently (so I took this over).

Whatever, who knows 😂 .

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted
8 hours ago, SOLVE-SMART said:

Hi @Davidyese 👋 ,

the following is definitely not my best code, but I did not want to change your approach too much.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y

#include-once
#include <Array.au3>

_Main()

Func _Main()
    Local Const $sSAPLocals = "ar|en|fr|d|ru|es|it|tr"
    Local Const $aLangfiles = StringSplit($sSAPLocals, "|", 2)

    Local Const $sTarget    = "sap-x64-301.exe|sap-x64-301ar.exe|sap-x64-301am.exe|sap-x64-301az.exe|sap-x64-301bg.exe|sap-x64-301ca.exe|sap-x64-301sc.exe|sap-x64-301tc.exe|sap-x64-301cro.exe|sap-x64-301cz.exe|sap-x64-301dk.exe|sap-x64-301nl.exe|sap-x64-301eu.exe|sap-x64-301fi.exe|sap-x64-301fr.exe|sap-x64-301gl.exe|sap-x64-301d.exe|sap-x64-301el.exe|sap-x64-301he.exe|sap-x64-301hu.exe|sap-x64-301id.exe|sap-x64-301it.exe|sap-x64-301jp.exe|sap-x64-301kr.exe|sap-x64-301lt.exe|sap-x64-301mn.exe|sap-x64-301no.exe|sap-x64-301pl.exe|sap-x64-301pt.exe|sap-x64-301br.exe|sap-x64-301ro.exe|sap-x64-301ru.exe|sap-x64-301srbcyr.exe|sap-x64-301sk.exe|sap-x64-301slv.exe|sap-x64-301es.exe|sap-x64-301sw.exe|sap-x64-301th.exe|sap-x64-301tr.exe|sap-x64-301uk.exe|sap-x64-301vn.exe"
    Local Const $aFiles     = StringSplit($sTarget, "|", 2)

    Local Const $sX64SAPValue = "301"

    Local $sSAPLngs
    Local $sGoodLatestx64

    For $i = 0 To UBound($aFiles) - 1
        For $ix = 0 To UBound($aLangfiles) - 1
            $sSAPLngs = $aLangfiles[$ix]
            If StringInStr($aFiles[$i], $sX64SAPValue & '.exe') Then
                $sGoodLatestx64 &= 'https://www.sap.com/sap/SAP-' & $sX64SAPValue & '.exe' & @CRLF
            EndIf
            If StringInStr($aFiles[$i], $sSAPLngs & '.exe') Then
                $sGoodLatestx64 &= 'https://www.sap.com/sap/SAP-' & $sX64SAPValue & $sSAPLngs & '.exe' & @CRLF
            EndIf
        Next
    Next

    Local $sGoodLatestx64WithoutLastCRLF = StringTrimRight($sGoodLatestx64, 2)

    Local Const $aGoodLatestX64 = StringSplit($sGoodLatestx64WithoutLastCRLF, @CRLF, BitOr(1, 2))

    Local $aUniqueList = _ArrayUnique($aGoodLatestX64)
    _ArraySort($aUniqueList)
    _ArrayDelete($aUniqueList, 0)

    $sGoodLatestx64 = _ArrayToString($aUniqueList, @CRLF)
    _WriteFile($sGoodLatestx64)

EndFunc

Func _WriteFile($sData)
    Local $hFileOpen = FileOpen(@ScriptDir & '\Down_Links.txt', 2)
    FileWrite($hFileOpen, "SAP x64" & @CRLF)
    FileWrite($hFileOpen, $sData)
    FileClose($hFileOpen)
EndFunc

Output:

SAP x64
https://www.sap.com/sap/SAP-301.exe
https://www.sap.com/sap/SAP-301ar.exe
https://www.sap.com/sap/SAP-301d.exe
https://www.sap.com/sap/SAP-301es.exe
https://www.sap.com/sap/SAP-301fr.exe
https://www.sap.com/sap/SAP-301it.exe
https://www.sap.com/sap/SAP-301ru.exe
https://www.sap.com/sap/SAP-301tr.exe

In case you want to avoid the long unreadable files string:

  Reveal hidden contents
Local Const $aFiles[] = _
    [ _
        'sap-x64-301.exe', _
        'sap-x64-301am.exe', _
        'sap-x64-301ar.exe', _
        'sap-x64-301az.exe', _
        'sap-x64-301bg.exe', _
        'sap-x64-301br.exe', _
        'sap-x64-301ca.exe', _
        'sap-x64-301cro.exe', _
        'sap-x64-301cz.exe', _
        'sap-x64-301d.exe', _
        'sap-x64-301dk.exe', _
        'sap-x64-301el.exe', _
        'sap-x64-301es.exe', _
        'sap-x64-301eu.exe', _
        'sap-x64-301fi.exe', _
        'sap-x64-301fr.exe', _
        'sap-x64-301gl.exe', _
        'sap-x64-301he.exe', _
        'sap-x64-301hu.exe', _
        'sap-x64-301id.exe', _
        'sap-x64-301it.exe', _
        'sap-x64-301jp.exe', _
        'sap-x64-301kr.exe', _
        'sap-x64-301lt.exe', _
        'sap-x64-301mn.exe', _
        'sap-x64-301nl.exe', _
        'sap-x64-301no.exe', _
        'sap-x64-301pl.exe', _
        'sap-x64-301pt.exe', _
        'sap-x64-301ro.exe', _
        'sap-x64-301ru.exe', _
        'sap-x64-301sc.exe', _
        'sap-x64-301sk.exe', _
        'sap-x64-301slv.exe', _
        'sap-x64-301srbcyr.exe', _
        'sap-x64-301sw.exe', _
        'sap-x64-301tc.exe', _
        'sap-x64-301th.exe', _
        'sap-x64-301tr.exe', _
        'sap-x64-301uk.exe', _
        'sap-x64-301vn.exe' _
    ]

 

It works, but it's not very flexible and also without error handling. If it's still okay for your goal, fine 🤝 .

Best regards
Sven

Thanks for your code but the code is not flexible and the code is something long, but usable for me and working

 

Posted
7 hours ago, Nine said:

Here my take with SRE :

#include <Array.au3>
#include <Constants.au3>

Local $sTarget = "sap-x64-301.exe|sap-x64-301ar.exe|sap-x64-301am.exe|sap-x64-301az.exe|sap-x64-301bg.exe|sap-x64-301ca.exe|sap-x64-301sc.exe|sap-x64-301tc.exe|sap-x64-301cro.exe|sap-x64-301cz.exe|sap-x64-301dk.exe|sap-x64-301nl.exe|sap-x64-301eu.exe|sap-x64-301fi.exe|sap-x64-301fr.exe|sap-x64-301gl.exe|sap-x64-301d.exe|sap-x64-301el.exe|sap-x64-301he.exe|sap-x64-301hu.exe|sap-x64-301id.exe|sap-x64-301it.exe|sap-x64-301jp.exe|sap-x64-301kr.exe|sap-x64-301lt.exe|sap-x64-301mn.exe|sap-x64-301no.exe|sap-x64-301pl.exe|sap-x64-301pt.exe|sap-x64-301br.exe|sap-x64-301ro.exe|sap-x64-301ru.exe|sap-x64-301srbcyr.exe|sap-x64-301sk.exe|sap-x64-301slv.exe|sap-x64-301es.exe|sap-x64-301sw.exe|sap-x64-301th.exe|sap-x64-301tr.exe|sap-x64-301uk.exe|sap-x64-301vn.exe"

Local $aList = StringRegExp($sTarget, "sap-x64-301(?||ar|en|fr|d|ru|es|it|tr)\.exe", $STR_REGEXPARRAYGLOBALMATCH)
$aList = _ArrayUnique($aList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)
Local $hFile = FileOpen("Down_Links.txt", $FO_OVERWRITE)
FileWriteLine($hFile, "SAP x64")
For $sLink In $aList
  FileWriteLine($hFile, "https://www.sap.com/sap/" & $sLink)
Next
FileClose($hFile)

I get also EN link.

SAP x64
https://www.sap.com/sap/sap-x64-301.exe
https://www.sap.com/sap/sap-x64-301ar.exe
https://www.sap.com/sap/sap-x64-301fr.exe
https://www.sap.com/sap/sap-x64-301d.exe
https://www.sap.com/sap/sap-x64-301it.exe
https://www.sap.com/sap/sap-x64-301ru.exe
https://www.sap.com/sap/sap-x64-301es.exe
https://www.sap.com/sap/sap-x64-301tr.exe

 

Working , easy code and suitable for me.

Thanks a lot for your help and this a good solution for me.

By the way the links are imaginary links just to understand  the code

Posted
18 hours ago, SOLVE-SMART said:

Thanks @Nine, I missed that one. I like your approach - it's basically the one I also had chosen.
One little thing: Your URLs are not named like Davidyese want it to.

@Davidyese: I adjusted my "solution". But let us know, are the created URLs valid?
https://www.sap.com/sap/SAP-301fr.exe ==> can only be downloaded when you're signed in, right?

Best regards
Sven

All links are imaginary to just understand the real code, your code is good and working nice and as you said it's not far from my code

You added some parts which make the code working 

Thanks my dear

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
  • Recently Browsing   0 members

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