[Résolu] récupérer texte dans page html
#1
Bonjour,
Je souhaiterai si possible un script permettant de récupérer une information sur une page html par l'eggdrop et la dire sur un salon. Il s'agit en fait d'un titre d'une musique ainsi que l'artiste sur cette page:  https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=text ou https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=json
Bien sur l'afficher à chaque fois aussi que celle-ci change. Merci
Cordialement.
Répondre Avertir
#2
This one, gets song data from first link (in "text" format)
.chanset #channel +radioking to activate on your channel.

this script requires tls : http://sourceforge.net/projects/tls/

TCL
set link "https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=text"
 
bind time - "* * * * *" radio_chk
 
proc radio_chk {args} {
    foreach chan [channels] {
if {[channel get $chan radioking]} {
     set songdb "radio.db"
     set oldsong [read_song $songdb]
     set newsong [fetch_song $::link]
 #set artist [lindex [split [fetch_song $::link] -] 0]
 #set title [lindex [split [fetch_song $::link] -] 1]
 #if {$artist in [stripcodes bcruag $oldsong] && $title in [stripcodes bcruag $oldsong]} { continue }
 #putserv "PRIVMSG $chan :\002$artist\002 - \00304$title\003"
 #write_song $songdb "\002$artist\002 - \00304$title\003" 
        if {[string match $newsong $oldsong]} { continue }
             putserv "PRIVMSG $chan :$newsong"
             write_song $songdb $newsong 
         }
     } 
}
 
proc fetch_song {url} {
     package require http
     package require tls
     ::http::register https 443 [list ::tls::socket -tls1 0 -ssl3 0]
     set token [::http::geturl $url]
     set data [::http::data $token]
     return $data
     ::http::cleanup $token
     ::http::unregister https
}
 
proc write_song {dbfile data} {
    set fp [open $dbfile w]
    puts $fp $data
    close $fp
}
 
proc read_song {dbfile} {
   if {![file exists $dbfile] || ![file readable $dbfile]} { return 0 }
         set fp [open $dbfile r]
         set dt [gets $fp] 
        close $fp
        return $dt
}
 
setudef flag radioking



and this one for second link you gave. ( for "json" format)
This one requires tcllib's json package and tls : http://sourceforge.net/projects/tls/

TCL
set link "https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=json"
 
bind time - "* * * * *" radio_chk
 
proc radio_chk {args} {
    foreach chan [channels] {
if {[channel get $chan radioking]} {
      set songdb "radio.db"
      set oldsong [read_song $songdb]
      set songdict [fetch_song $::link]
 #set newsong "\002[dict get $songdict artist]\002 - \00304[dict get $songdict title]\003"
      set newsong "\002[dict get $songdict artist]\002 - \00304[dict get $songdict title]\003 - \037[dict get $songdict cover]\037"
        if {[string match $newsong $oldsong]} { continue }
             putserv "PRIVMSG $chan :$newsong"
             write_song $songdb $newsong 
        }
    } 
}
 
proc fetch_song {url} {
     package require http
     package require tls
     package require json
     ::http::register https 443 [list ::tls::socket -tls1 0 -ssl3 0]
     set token [::http::geturl $url]
     set data [::json::json2dict [::http::data $token]]
     return $data
     ::http::cleanup $token
     ::http::unregister https
}
 
proc write_song {dbfile data} {
    set fp [open $dbfile w]
    puts $fp $data
    close $fp
}
 
proc read_song {dbfile} {
   if {![file exists $dbfile] || ![file readable $dbfile]} { return 0 }
         set fp [open $dbfile r]
         set dt [gets $fp] 
         close $fp
         return $dt
}
 
setudef flag radioking


Répondre Avertir
#3
Tout d'abord merci de ton aide.
J'ai bien rentré ce tcl dans mon eggdrop le format text mais je n'ai rien qui s'affiche du tout et aucun message d'erreur.
Répondre Avertir
#4
I've just tried and tested first code on a bot. (eggdrop1.8 , Tcl 8.6.4 )

I uploaded script in to my bot/scripts and added source scripts/radioking.tcl line into my bot's .conf file:
http://i.imgur.com/vV6Bs8S.png

then i've connected to my bot via telnet
and i typed .rehash first:
http://i.imgur.com/F6Johz8.png

then to activate this script on a #channel,
.chanset #channel +radioking
http://i.imgur.com/f0ltoqi.png

and my bot started posting new songs on #channel
like you've wanted if i understood your request correct before.
http://i.imgur.com/lwe9Ns4.png

These radioking links has https needs tls ,
if you've .tcl .set commands enabled on your bot's .conf ,
.tcl package present tls
to check if it could see this package.

this : .tcl package present tls command should return tls version.
if it doesn't return any value and if you've already installed this,
you could try to add a line like:
lappend ::auto_path /path/to/tls

right before the : package require tls
or you can add this on bot's .conf
this may help to find this tls package has been located on the system.
Répondre Avertir
#5
i send ou a MP Wink
Répondre Avertir
#6
Bonjour ,
j'ai une erreur TCL:
Tcl error [radio_chk]: no valid protocol selected
Je suis en tcl 8.5 et eggdrop 1.6.21
Répondre Avertir


Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté