Sign in to follow this  
Followers 0
SmartiePants

Link Enumerator

6 posts in this topic

#1 ·  Posted (edited)

I have put together a somewhat crude script that is supposed to find numbers within the supplied link, tell the user those number locations and prompt which one should be enumerated, meaning the script would generate links with that particular number incremented. script worked well for an example link http://www.russki-razmer.spb.ru/photo/1.jpg but did not for http://www.russki-razmer.spb.ru/photo/pivnoi06/1.jpg - it has a fault with the display of .......#-#..., but that is temporary, for I could not put together a more elaborate solution for display of the found number locations. The main problem is that with 06/1.jpg the script enumerated the / instead of digits... I have spent too much time on it that I can't think straight and was hoping someone could help me a bit :( Thanks..

Updated code as of ...the time and date of the update of the post :) It is clumsy, but works. The script figures out locations of the #'s within the string/link supplied, prompts which to enumerate if there is more than 1, then, if the string starts with Zeros (ex: www.moocow.com/0006/index.html), output would yield 0006 to be 0007 instead of just 7, when enumerated # reaches 10, 100, 1000, zeros are displaced to contain less, otherwise the number is simply enumerated to the amount specified by the user in the next step. Hope I said that right.. 4:30am, college in the morning *goes to bed* ;) Anyone is free to simplify my script at the cost of their time and effort and share with me the results :mellow:

; plans: to enable $numSelect input to be of 7-1,14-4 format
; where 7 is the starting character for # to enumerate and 1 is the number of characters that should be enumerated,
; thus forcing the digit enumeration to a specific section instead of the whole # within the link.
AutoItSetOption("TrayIconHide", 1)
ToolTip("http://www.russki-razmer.spb.ru/photo/1.jpg" & @CR & "Note: make sure # starts with smallest available, normally 1, such as the 1.jpg", 300, 0, "Base link example:")
$lnkInput = InputBox("Base Link", "Enter base link for enumeration", "", "", 300, 115)
If $lnkInput = "" Then Exit
ToolTip(@ScriptDir & "\LinkOut.txt", 300, 0, "Output file will be...")
$len = StringSplit($lnkInput, "")
Global $arrOccurence[$len[0] + 1][2]
Global $arrNum[1][2]
Global $strOutput = ""
$arrOccurence[0][0] = $len[0]
For $l = 1 To $len[0]
    Switch $len[$l]
        Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
            $numChk = 1
        Case Else
            $numChk = 0
    EndSwitch
    If Not $numChk = 0 Then
        $arrOccurence[$l][0] = 1
    Else
        $arrOccurence[$l][0] = 0
    EndIf
Next

$c = 1; check if 1st dim has 1 and store # in 2nd dim
For $o = 1 To $arrOccurence[0][0]; - 1
    $arrOccurence[$o][1] = 0
    If $arrOccurence[$o][0] = 1 Then
        $arrOccurence[$c][1] += 1
    Else
        $c = $o + 1
    EndIf
Next

$r = 1
For $n = 1 To $arrOccurence[0][0] - 1
    If $arrOccurence[$n][1] > 0 Then
        $r += 1
        ReDim $arrNum[$r][2]
        $arrNum[$r - 1][0] = $n; location of # start
        $arrNum[$r - 1][1] = $arrOccurence[$n][1]; number of #'s
    EndIf
Next

$arrNum[0][0] = UBound($arrNum)
For $p = 1 To $arrNum[0][0] - 1
    For $y = 1 To $arrNum[$p][0] - 1
        $strOutput = $strOutput & ".";Chr(32)
    Next
    $strOutput = $strOutput & $arrNum[$p][0]
    For $z = $arrNum[$p][0] To $arrNum[$p][0] + $arrNum[$p][1] - 1
        $strOutput = $strOutput & "-";Chr(32)
    Next
    $strOutput = $strOutput & $arrNum[$p][1]
Next
ToolTip("Ex. calculation of # locations: .....7-1.....15-4" & @CR & "7 and 15 are starting characters" & @CR & "1 and 4 is the amount of characters in the # within the link (ignore them)", 300, 0, "Input the correct occurence that should be enumerated")

If $arrNum[0][0] > 2 Then
    $numSelect = InputBox("Input 1st # for selection", $strOutput & @CR & $lnkInput, "", "", 500, 125)
    If $numSelect = "" Then Exit
Else
    $numSelect = $arrNum[1][0]
EndIf
$lnkLeft = StringLeft($lnkInput, $numSelect - 1)

For $x = 1 To $arrNum[0][0] - 1
    If $arrNum[$x][0] = $numSelect Then
        $limRight = $arrNum[$x][1]
    EndIf
Next
$lnkRight = StringRight($lnkInput, StringLen($lnkInput) - ($numSelect + $limRight - 1))
ToolTip("Ex: 100", 300, 0, "You surely want a limit on the # of links generated")
$limit = InputBox("Limit", "How many links to generate?", "", "", 300, 125)
$lnkNumEnum = StringMid($lnkInput, $numSelect, $limRight)
; if $lnkNumEnum starts with zeros...
$numOriginal = $lnkNumEnum
$numBase = $numOriginal
$numSplit = StringSplit($numOriginal, "")
For $s = 1 To $numSplit[0] - 1
    If $numSplit[$s] = "0" Then
        $numLeft = StringLeft($numOriginal, $s)
        $numBase = StringRight($numOriginal, StringLen($numOriginal) - 1)
    EndIf
Next

Global $numLenOld, $numLeft
$numBase = Number($numBase)
$numLenOld = StringLen($numBase)

$fileOutput = FileOpen(@ScriptDir & "\LinkOut.txt", 2)
If $fileOutput = -1 Then
    MsgBox(16, "Error", "Cannot create output file!")
    Exit
EndIf
For $j = $lnkNumEnum To $lnkNumEnum + $limit
    ToolTip("Link #" & $j, 300, 0)
    $numLen = StringLen($numBase)
    If $numLen > $numLenOld Then
        $numLeft = StringLeft($numLeft, StringLen($numLeft) - 1)
    EndIf
    $numLenOld = $numLen
    $numFinal = String($numLeft & $numBase)
    $numBase += 1
    FileWriteLine($fileOutput, $lnkLeft & $numFinal & $lnkRight)
Next
ToolTip("")
FileClose($fileOutput)
Edited by SmartiePants

[font="Comic Sans MS"]It's my first day.[/font]View and move images to subdirectories by pressing a key in XnView

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$URL = "http://www.russki-razmer.spb.ru/photo/pivnoi06/1.jpg"
MsgBox(0, "TEST", _FileNum($URL))
Func _FileNum($sStr)
   $aRegEx = StringRegExp($sStr, "(?i)/(\d*\.jpg)", 1)
   If NOT @Error Then Return $aRegEx[0]
EndFunc

Another way of doing it would be.

$URL = "http://www.russki-razmer.spb.ru/photo/pivnoi06/1.jpg"
$URL = StringMid($URL, StringInStr($URL, "/", 0, -1) +1)
MsgBox(0, "TEST", $URL)

And yet another

$URL = "http://www.russki-razmer.spb.ru/photo/pivnoi06/1.jpg"
$URL = StringRegExpReplace($URL, "(?i)(.+/)(\d*\.\w+)", "\2")
MsgBox(0, "TEST", $URL)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

The original idea behind the script was to identify number locations within a given string, such as a link, prompt the user with a selection of number locations that were found, that can be used for further enumeration of the base string/link that is not specific to .jpg ending of the string, nor limited to just one number within the string. I must admit I like the code with regular expressions (which I do not use yet because they are confusing), but I do not see how it is applicable to the script I was trying to make :mellow:

So if I understand you correctly, you want just the number portion of the filename returned. Is that correct?

Example;

1.jpg = 1

23.jpg = 23

64.gif = 64

&etc ad infinitum

If this is correct then it's an easy change to any of the three I posted.

Just let me know precisly what you need returned.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

So if I understand you correctly, you want just the number portion of the filename returned. Is that correct?

Example;

1.jpg = 1

23.jpg = 23

64.gif = 64

&etc ad infinitum

If this is correct then it's an easy change to any of the three I posted.

Just let me know precisly what you need returned.

That is one of the purposes, whereas the other would be to enumerate a number in the middle of the link. Ex: http://www.moocow.com/page1234/1.html - where I want to enumerate only the 1234 portion and not the 1.html

I wanted the script to be able to figure out where numbers are and then give the ability to the user to select what should be enumerated. Sort of like human logic as we see a string of text and know that we should only change a specific section of it and leave the rest as is. I think there is more use to such a script than just web links' enumeration :mellow: I might be able to figure out my own mistakes though...


[font="Comic Sans MS"]It's my first day.[/font]View and move images to subdirectories by pressing a key in XnView

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well, it seems I can't create a coherent means of displaying the locations of found numbers so that the user can select what shall be enumerated. I tried to make a GUI, but saw the shortcoming of control generation, as their names should be hard-coded. I thought of using an IE window with proper javascript because it is much easier to display elements in a web page than in a GUI, but javascript must store values in some hidden element within the webpage, which can later be read. I guess my only problem is having those "hidden" values stored somewhere by javascript. here is the script code with added GUI that I have added so far. If someone has great ideas on how I should display the found number locations, speak your mind. Thanks.

#include <GUIConstants.au3>
#include <IE.au3>
; plans: to enable $numSelect input to be of 7-1,14-4 format
; where 7 is the starting character for # to enumerate and 1 is the number of characters that should be enumerated,
; thus forcing the digit enumeration to a specific section instead of the whole # within the link.
AutoItSetOption("TrayIconHide", 1)
ToolTip("http://www.russki-razmer.spb.ru/photo/1.jpg" & @CR & "Note: make sure # starts with smallest available, normally 1, such as the 1.jpg", 300, 0, "Base link example:")
$lnkInput = InputBox("Base Link", "Enter base link for enumeration", "", "", 300, 115)
If $lnkInput = "" Then Exit
ToolTip(@ScriptDir & "\LinkOut.txt", 300, 0, "Output file will be...")
$len = StringSplit($lnkInput, "")
Global $arrOccurence[$len[0] + 1][2]
Global $arrNum[1][2]
Global $strOutput = ""
$arrOccurence[0][0] = $len[0]
For $l = 1 To $len[0]
    Switch $len[$l]
        Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
            $numChk = 1
        Case Else
            $numChk = 0
    EndSwitch
    If Not $numChk = 0 Then
        $arrOccurence[$l][0] = 1
    Else
        $arrOccurence[$l][0] = 0
    EndIf
Next

$c = 1; check if 1st dim has 1 and store # in 2nd dim
For $o = 1 To $arrOccurence[0][0]; - 1
    $arrOccurence[$o][1] = 0
    If $arrOccurence[$o][0] = 1 Then
        $arrOccurence[$c][1] += 1
    Else
        $c = $o + 1
    EndIf
Next

$r = 1
For $n = 1 To $arrOccurence[0][0] - 1
    If $arrOccurence[$n][1] > 0 Then
        $r += 1
        ReDim $arrNum[$r][2]
        $arrNum[$r - 1][0] = $n; location of # start
        $arrNum[$r - 1][1] = $arrOccurence[$n][1]; number of #'s
    EndIf
Next

$arrNum[0][0] = UBound($arrNum)
$moo = 0
$cow = 0
; ########### temporary solution #########
For $p = 1 To $arrNum[0][0] - 1
    If $moo = 0 Then
        For $y = 1 To $arrNum[$p][0] - 1
            $cow = $arrNum[$p][0]
            $strOutput = $strOutput & ".";Chr(32)
        Next
    Else
        For $y = 1 To $arrNum[$p][0] - 1
            $cow1 = $arrNum[$p][0]
        Next
        For $y = 1 To $cow1 - $cow
            $strOutput = $strOutput & ".";Chr(32)
        Next
    EndIf
    
    $strOutput = $strOutput & $arrNum[$p][0]
    For $z = $arrNum[$p][0] To $arrNum[$p][0] + $arrNum[$p][1] - 1
        $strOutput = $strOutput & "-";Chr(32)
    Next
    $strOutput = $strOutput & $arrNum[$p][1]
    $moo += 1
Next
ToolTip("Ex. calculation of # locations: .....7-1.....15-4" & @CR & "7 and 15 are starting characters" & @CR & "1 and 4 is the amount of characters in the # within the link (ignore them)", 300, 0, "Input the correct occurence that should be enumerated")
; ################### GUI ##################
GUICreate("Select Numbers", 800, 120)
$oIE = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($oIE, 0, 0, 800, 56); 56
GUICtrlCreateInput("", 0, 56, 800, 30); 86
$Submit = GUICtrlCreateButton("Enumerate", 0, 86, 800, 34)
GUISetState()

FileWriteLine("temp.html", '<html><head></head><body bgcolor="black">')
; start element html code
For $a = 1 To $len[0]
    If $arrOccurence[$a][0] = 1 Then
        FileWrite("temp.html", "<b><font color='green'>" & $len[$a] & "</font></b>")
    Else
        FileWrite("temp.html", "<font color='white'>" & $len[$a] & "</font>")
    EndIf
Next
; end element html code
FileWrite("temp.html", '</body></html>')
$oIE.navigate(@WorkingDir & "\temp.html")
_IELoadWait($oIE)
Do
       ; collect hidden IE content and show it in the Inputbox control
;$GuiInput = _IEGetObjByName($oIE, "")
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            FileDelete("temp.html")
            Exit
        Case $msg = $Submit
               ; fix this code
            FileDelete("temp.html")
            ExitLoop
    EndSelect
Until 0

; #####################################
If $arrNum[0][0] > 2 Then
    $numSelect = InputBox("Input 1st # for selection", $strOutput & @CR & $lnkInput, "", "", 800, 125)
    If $numSelect = "" Then Exit
Else
    $numSelect = $arrNum[1][0]
EndIf
$lnkLeft = StringLeft($lnkInput, $numSelect - 1)

For $x = 1 To $arrNum[0][0] - 1
    If $arrNum[$x][0] = $numSelect Then
        $limRight = $arrNum[$x][1]
    EndIf
Next
$lnkRight = StringRight($lnkInput, StringLen($lnkInput) - ($numSelect + $limRight - 1))
ToolTip("Ex: 100", 300, 0, "You surely want a limit on the # of links generated")
$limit = InputBox("Limit", "How many links to generate?", "", "", 300, 125)
$lnkNumEnum = StringMid($lnkInput, $numSelect, $limRight)
; if $lnkNumEnum starts with zeros...
$numOriginal = $lnkNumEnum
$numBase = $numOriginal
$numSplit = StringSplit($numOriginal, "")
For $s = 1 To $numSplit[0] - 1
    If $numSplit[$s] = "0" Then
        $numLeft = StringLeft($numOriginal, $s)
        $numBase = StringRight($numOriginal, StringLen($numOriginal) - 1)
    EndIf
Next

Global $numLenOld, $numLeft
$numBase = Number($numBase)
$numLenOld = StringLen($numBase)

$fileOutput = FileOpen(@ScriptDir & "\LinkOut.txt", 2)
If $fileOutput = -1 Then
    MsgBox(16, "Error", "Cannot create output file!")
    Exit
EndIf
For $j = $lnkNumEnum To $lnkNumEnum + $limit
    ToolTip("Link #" & $j, 300, 0)
    $numLen = StringLen($numBase)
    If $numLen > $numLenOld Then
        $numLeft = StringLeft($numLeft, StringLen($numLeft) - 1)
    EndIf
    $numLenOld = $numLen
    $numFinal = String($numLeft & $numBase)
    $numBase += 1
    FileWriteLine($fileOutput, $lnkLeft & $numFinal & $lnkRight)
Next
ToolTip("")
FileClose($fileOutput)
Edited by SmartiePants

[font="Comic Sans MS"]It's my first day.[/font]View and move images to subdirectories by pressing a key in XnView

Share this post


Link to post
Share on other sites

Sorry, I forgot all about this one. Try this RegExp.

$sStr = "http://www.moocow.com/page1234/1.html"
$aRegEx = StringRegExp($sStr, "\D+([\d|\.\w]*)\b", 3)
If IsArray($aRegEx) Then
   For $i = 0 to Ubound($aRegEx) -1
      MsgBox(0, "TEST", $aRegEx[$i])
   Next
EndIf

If you don't want the extension to show at any time then change $aRegEx to

$aRegEx = StringRegExp($sStr, "\D+(\d*[^[:punct:]|[:alpha:]])", 3)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0