Jump to content

My First Script! - Error parsing call


Recommended Posts

I'm trying to pull prices on whey from a couple sites so I can easily check who's cheapest when I need to order more.

I get an error on line 33 (the first time i try to call one of my functions). Can you even do what I'm trying to do? call in a call in a call.

;includes
#include <ie.au3>
#include <excel.au3>
#include <array.au3>
#include <file.au3>
#include <string.au3>
#include <inet.au3>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

;globals nigga
Global $sectionarry[12] = ["amazon product name", "amazon price", "amazon url", "gnc productname", "gnc price", "gnc url", "bodybuilding product name", "bodybuilding price", "bodybuilding url", "vitaminshoppe product name", "vitaminshoppe price", "vitaminshoppe url"]
Global $col = 3

;excel file, create if doesnt exist (format premade) then read and put urls into array
If FileExists("wheyurls.XLS") = 0 Then
    $oExcel = _ExcelBookNew()
    _ExcelBookSaveAs($oExcel, @ScriptDir & "\wheyurls.xls", "xls", 0, 0)
    For $i = 0 to UBound( $sectionarry, 1) - 1
        ;create excel file w/ columns at top
        _ExcelWriteCell($oExcel,$sectionarry[$i],1,$i + 1)
        _ExcelBookSave($oExcel)
    Next
EndIf
If FileExists("wheyurls.XLS") = 1 Then
    $oExcel=_ExcelBookOpen(@ScriptDir & "\wheyurls.xls")
EndIf

    Do
        If $col=3 Then
            Call("pricetocell",Call("_amazonprice",Call("urlfromarray",$col),$col)
            Call("nametocell",Call("_amazonname",Call("urlfromarray",$col),$col)
        ElseIf $col=6 Then
            Call("pricetocell",Call("_gncprice",Call("urlfromarray",$col),$col)
            Call("nametocell",Call("_gncname",Call("urlfromarray",$col),$col)
        ElseIf $col=9 Then
            Call("pricetocell",Call("_bodybuildingprice",Call("urlfromarray",$col),$col)
            Call("nametocell",Call("_bodybuildingname",Call("urlfromarray",$col),$col)
        Else
            Call("pricetocell",Call("_vitaminshoppeprice",Call("urlfromarray",$col),$col)
            Call("nametocell",Call("_vitaminshoppename",Call("urlfromarray",$col),$col)
        EndIf
        $col+=3
    Until $col=12
_ExcelBookSave($oExcel)



Func getnumberurl($col) ;gets the number of urls in column
    Local $int_url = 0
    For $i = 2 To $oExcel.ActiveSheet.UsedRange.Rows.Count
        $s_check = _ExcelReadCell($oExcel,$i,$col)
        If IsString($s_check) = 1 Then
            $int_url+=1 ;int url is the # of urls in the column
        Else
        EndIf
    Next
    Return $int_url ;number of urls in the column
EndFunc

Func readurl($col) ;takes in column
    $arrayurl = _ExcelReadArray($oExcel,2,$col,Call("getnumberurl",$col),1)
    Return $arrayurl ;0 based array of urls
EndFunc

Func urlfromarray($col) ;input column, create array of all urls then returns url string
    $arrayurl = Call("readurl",$col)
    For $k = 0 To UBound($arrayurl,1) - 1
        $url = $arrayurl[$k]
    Next
    Return $url
EndFunc ;output url string

Func pricetocell($s_price,$col)
    For $p = 2 to UBound(Call("readurl",$col), 1)
    _ExcelWriteCell($oExcel,$s_price,$p,$col - 1)
    Next
EndFunc

Func nametocell($s_name,$col)
    For $p = 2 to UBound(Call("readurl",$col), 1)
    _ExcelWriteCell($oExcel,$s_name,$p,$col - 2)
    Next
EndFunc

;
;
;

Func _amazonprice($s_url) ;input url string
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<b class="priceLarge">',"</b>")
    Return $aArray[0]
EndFunc ;output price string

Func _amazonname($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<span id="btAsinTitle">',"</span>")
    Return $aArray[0]
EndFunc

;
;
;

Func _gncprice($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<span class="priceNow">Price: ',"</span>")
    Return $aArray[0]
EndFunc

Func _gncname($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<span id="btAsinTitle">',"</span>")
    Return $aArray[0]
EndFunc

;
;
;

Func _bodybuildingprice($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<span class="price">',"</span>")
    Return $aArray[0]
EndFunc

Func _bodybuildingname($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'</span>',"</h1>")
    $aArray[0] = StringReplace($aArray[0], '"', "") ;gets rid of quotes
    $aArray[0] = StringReplace($aArray[0], " ", "") ;gets rid of spaces
    Return $aArray[0]
EndFunc

;
;
;

Func _vitaminshoppeprice($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<li class="saleValue-Price">Your Price: ',"</li>")
    Return $aArray[0]
EndFunc

Func _vitaminshoppename($s_url)
    $s_urlbody = _INetGetSource($s_url,"true")
    $aArray = _StringBetween($s_urlbody,'<h1 class="prdTitle">',"</h1>")
    Return $aArray[0]
EndFunc
Link to comment
Share on other sites

Not necessary to use call.

Call("pricetocell",Call("_amazonprice",Call("urlfromarray",$col),$col)

can be written as:

pricetocell(_amazonprice(urlfromarray($col)),col)

I removed one $col because _amazonprice only accepts one parameter.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Not necessary to use call.

Call("pricetocell",Call("_amazonprice",Call("urlfromarray",$col),$col)

can be written as:

pricetocell(_amazonprice(urlfromarray($col)),col)

I removed one $col because _amazonprice only accepts one parameter.

Thank you so much! I've gotten past that and now my $aArray variable in line 99 func _amazonname (gets product name from amazon's website) isn't returning anything (Error: subscript used with non array variable.) This is strange because I thought _stringbetween returned a 0 based array.

Also, does this look super convoluted or is this how anyone would approach doing what I'm trying to do in autoit?

Link to comment
Share on other sites

You need to do some error checking in your script. _INetGetSource sets @error if it wasn't successful.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...