Code: Select all
set line "I have had a new experience last week"
if { [regexp -all -nocase -- {have had (.+?) exp} $line -> catch] } {
set catch $catch
}
puts "catch1: $catch"
set line2 "I have had an extraordinary experience last week"
if { [regexp -all -nocase -- {have had (.+?) exp} $line2 -> catch2] } {
set catch2 $catch2
}
puts "catch2: $catch2"
Code: Select all
(Tcl) % source regexmiddle.tcl
catch1: a new
catch2: an extraordinary
(Tcl) %
Code: Select all
proc SpotInfo_proc { nick uhost hand chan arg } {
if { [regexp -all -nocase -- {http://open.spotify.com/track/(^.{22}$)} $line2 -> spotCode] } {
set data_lines [grab_http_data 2 http://mysite/check?code= $spotCode]
}
}
proc grab_http_data { type url query arg } {
set user_agent "http-query.tcl <eggdrop script>"
set tiny_token [http::config -useragent $user_agent]
if {$type == 1} {
set tiny_token [http::geturl $url -timeout 10000]
} else {
set proper_url "$url?$query=$arg"
set tiny_token [http::geturl $proper_url -timeout 10000]
}
set html_data [http::data $tiny_token]
if {$html_data != ""} {
return $html_data
} {
return "error"
}
}
Code: Select all
[regexp -all -nocase -- {words1 (.+?) words2} $line2 -> spotCode]
Code: Select all
set urls {
http://open.spotify.com/track/75JFxkI2RXiU7L9VXzMkle
http://open.spotify.com/track/3yV98lWu83L5RZZ6RKoUg9
http://open.spotify.com/track/4OSRg1faLprPCt86C80zWt
http://open.spotify.com/track/3ou9rSNUQnE7XYmJkUUIOc
http://open.spotify.com/track/3QkNkun3dzkeGo1jpkC76S
}
foreach listedurl $urls {
set newurl [string map { "http://open.spotify.com/track/" "" } $listedurl]
puts "http://mysite.com/check?code=$newurl"
}
Code: Select all
(Tcl) % source urltest.tcl
http://mysite.com/check?code=list
http://mysite.com/check?code=75JFxkI2RXiU7L9VXzMkle
http://mysite.com/check?code=3yV98lWu83L5RZZ6RKoUg9
http://mysite.com/check?code=4OSRg1faLprPCt86C80zWt
http://mysite.com/check?code=3ou9rSNUQnE7XYmJkUUIOc
http://mysite.com/check?code=3QkNkun3dzkeGo1jpkC76S
(Tcl) %
Code: Select all
proc SpotInfo_proc {nick uhost hand chan arg} {
if {[regexp -nocase -- {(?:http://open\.spotify\.com/track/|spotify:track:)([[:alnum:]]{22})} $arg spotify track]} {
set data_lines [grab_http_data 2 http://mysite/check?code=${track}]
}
}
Code: Select all
bind pubm -|- * SpotInfo_proc
package require http
proc SpotInfo_proc {nick uhost hand chan arg} {
if {[regexp -nocase -- {(?:http://open\.spotify\.com/track/|spotify:track:)([[:alnum:]]{22})} $arg spotify track]} {
set data_lines [grab_http_data 2 http://mysite.com/spotInfo.php?uri=${track}]
}
}
proc grab_http_data { type url } {
set user_agent "http-query.tcl <eggdrop script>"
set tiny_token [http::config -useragent $user_agent]
if {$type == 1} {
set tiny_token [http::geturl $url -timeout 10000]
} else {
set proper_url "$url"
set tiny_token [http::geturl $proper_url -timeout 10000]
}
set html_data [http::data $tiny_token]
if {$html_data != ""} {
return $html_data
} {
return "error"
}
}
putlog "SpotInfo.tcl loaded"
And then[04:43] Tcl error [SpotInfo_proc]: wrong # args: should be "grab_http_data type url query arg"
But then I fixed the grab_http_data, but now it doesn't say anything.[04:49] Tcl error [SpotInfo_proc]: can't read "query": no such variable
Code: Select all
proc SpotInfo_proc {nick uhost hand chan arg} {
if {[regexp -nocase -- {(?:http://open\.spotify\.com/track/|spotify:track:)([[:alnum:]]{22})} $arg spotify track]} {
set data_lines [grab_http_data 2 http://mysite.com/spotInfo.php?uri=${track}]
if {![string equal $data_lines "error"]} {
foreach line [split $data_lines "\n"] {
puthelp "NOTICE $chan :$line"
}
}
}
}