AcidCorps Posted October 4, 2013 Share Posted October 4, 2013 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. expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 4, 2013 Moderators Share Posted October 4, 2013 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? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AcidCorps Posted October 4, 2013 Author Share Posted October 4, 2013 (edited) 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 October 4, 2013 by AcidCorps Link to comment Share on other sites More sharing options...
AcidCorps Posted October 4, 2013 Author Share Posted October 4, 2013 You were right thank you for your help Melba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 4, 2013 Moderators Share Posted October 4, 2013 AcidCorps,Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now