Mise en forme de code: pensez à utiliser les balises [ tcl ] et [ /tcl ] (sans les espaces bien sûr) autour de vos codes tcl afin d'avoir un meilleur rendu et une coloration syntaxique. x


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

Away
#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.
#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.
Away
#5
i send ou a MP ;)
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  récupérer un php T4tou 5 544 16/08/2021, 13:42
Last Post: CrazyCat
  [Demande] Script recupération dedicace sur une page web fedora 6 5,847 10/03/2015, 02:20
Last Post: angels
  [Demande] Récupérer le contenu de la timeline BetaSeries.com KiBa 1 3,593 29/10/2013, 15:12
Last Post: aliasangelius
  [Demande] Récupérer certaines infos dans fichier .user Hitsu 5 5,201 30/07/2013, 17:13
Last Post: CrazyCat
  [Recherche] TCL pour récupérer des infos sur un site Maxwell 14 8,838 04/05/2013, 10:50
Last Post: Maxwell
  Statistiques d'un canal dans une page HTML CrazyCat 12 7,772 14/02/2013, 12:37
Last Post: CrazyCat
  Lire les dernières lignes d'un fichier texte. Ryan 4 5,172 23/09/2012, 18:34
Last Post: CrazyCat
  Script servant à lire le contenu d'un fichier texte KiBa 4 5,951 07/03/2012, 16:14
Last Post: KiBa
  nick list dans fichier html loulou7593 20 11,943 04/02/2012, 18:43
Last Post: djkenny
  recuperer les infos d'une page web loulou7593 0 3,724 23/12/2011, 00:20
Last Post: loulou7593

Forum Jump:


Users browsing this thread: 1 Guest(s)