Jump to content
Sign in to follow this  
AcidCorps

Function accepts string but not variable (can pass "ACDC" but not $Band)

Recommended Posts

AcidCorps

I'm writing a script that will take a list of bands I make and suggest new bands based on them (I've done another version of this in the past but a hard drive crash took it away)

My problem is I've created a funciton _ArtistGetCorrection that tells me if the band name is spelled correctly. However if I pass a variable to it it tells me my api key is invalid but if it's a string it's valid.

For example

_ArtistGetCorrection("ACDC") will give me the correction where as

_ArtistGetCorrection($Favorites[$i]) will tell me that my API Key is invalid.

Sorry if the codes a bit choppy I've been trying to wrap my brain around this one for a little bit at the expense of organzied code.

#include <Test.au3>
#include <Constants.au3>


Dim $VoteList

Global $Bin = @ScriptDir & '\Bin\' & @CPUArch
$Wget = $Bin & '\wget --no-check-certificute '
$Curl = $Bin & '\curl.exe '
$myKey = ;Hidden

$Include = FileRead('include.txt')
$Favorites = _StringBetween($Include, '###Favorites###', '###Good Artists###')
$Favorites = StringSplit($Favorites[0], @CR)
$GoodArtists = _StringBetween($Include, '###Good Artists###', '###End###')
$GoodArtists = StringSplit($GoodArtists[0], @CR)
$Sim = _ArtistGetCorrection('Green Day')
Test($Sim)
$i = 0
Do
    If $Favorites[$i] = '' Or $Favorites[$i] = @LF Then
        _ArrayDelete($Favorites, $i)
    Else
        $i += 1
    EndIf
Until $i = Ubound($Favorites)
$i = 0
Do
    If $GoodArtists[$i] = '' Or $GoodArtists[$i] = @LF Then
        _ArrayDelete($GoodArtists, $i)
    Else
        $i += 1
    EndIf
Until $i = Ubound($GoodArtists) - 1
_ArrayDelete($Favorites, 0)
_ArrayDelete($GoodArtists, 0)
$i = 1
Test($Favorites[$i])
$Favorites[$i] = _ArtistGetCorrection($Favorites[$i])
$Favorites[$i] = _ArtistGetCorrection('Modest Mouse')
Test($Favorites)

Func _ArtistGetCorrection($iArtist)
    Local $Pid, $Return
    $Pid = Run($Curl & ' http://ws.audioscrobbler.com/2.0/?method=artist.getcorrection&artist=' & StringReplace($iArtist, ' ', '%20') & '&api_key=' & $myKey & '&format=json', $Bin, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $Return = ''
    While 1
        $Return &= StdoutRead($Pid)
        If @error Then ExitLoop
    WEnd
    $Return = StringTrimLeft($Return, StringINStr($Return, '":"') + 2)
    Test($Return)
    If StringInStr($Return, '\n                "}') Then
        Return $iArtist
    Else
        Return StringLeft($Return, STringINStr($Return, '","') - 1)
    EndIf
EndFunc   ;==>_ArtistGetCorrection

Func _ArtistGetSimilar($iArtist)
    Local $Pid, $Return
    $Pid = Run($Curl & ' http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=' & StringReplace($iArtist, ' ', '%20') & '&api_key=' & $myKey & '&format=json', $Bin, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $Return = ''
    While 1
        $Return &= StdoutRead($Pid)
        If @Error THen ExitLoop
    WEnd
    Return _StringBetween($Return, '"name":"', '","')
EndFunc   ;==>_ArtistGetSimilar

The only edit I've made is instead of storing my key in plain text in the url i've changed it to $myKey.

Share this post


Link to post
Share on other sites
Melba23

AcidCorps,

The obvious question is whether the string in $Favorites[$i] is identical to the text string which does work? If it is not then the total string you pass could well be failing when parsed for the next parameter. ;)

Have you checked for leading/trailing whitespace - you can remove this with StringStripWS - or perhaps a @CRLF at the end of the string? :huh:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
AcidCorps

I actually even used clip put and pasted it back in.

I'll do a double check for formatting though.

 

Still haven't finished going through but I'm thinking you may have been right. Maybe I tried the clip put before I edit something crucil.

Edited by AcidCorps

Share this post


Link to post
Share on other sites
AcidCorps

You were right thank you for your help Melba

Share this post


Link to post
Share on other sites
Melba23

AcidCorps,

Glad I could help. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×