This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

GoogleNews

Help for those learning Tcl or writing their own scripts.
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Modify the news_print procedure with the tip given @ http://forum.egghelp.org/viewtopic.php?t=11212
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

CrazyCat:
There is problem that BOT doesn't send News to all Its JOINED Channels, Is there any restriction in TCL of Joining Channels?

I will request you to edit it for that Bot send news to all channels whenver it sends.
Thanks.
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Google News

Post by Goga »

Code: Select all

# Google news v0.3 by nrt (01Dec2015)
# Updated GoogleNews Country links and added some more lines for redirected link support (04Jan2018) karakedi

package require tdom
package require http
package require htmlparse
package require textutil::split
package require tls 1.6.4
package present Tcl 8.6

set ::oldnews [list ]

set googlelink {https://news.google.com/news/rss/headlines/section/topic/NATION}

# Length of chars in a line.
set newsmax 300

# Links shortened to tinyurl. 1 = true , 0 = false
set tinyurl 1

# 1 = US_en (U.S.A), 2 = TR (Turkey) , 3 = FR (France), 4 = DE (Germany), 5 = UK_en (U.K) , 6 = RU (Russia)
# 7 = IT (Italy) , 8 = NL (Netherlands) , 9 = AU_en (Australia) , 10 = PT (Portugal) , 11 = AR (Arabian World) , 12 = AT_de (Austria)
# 13 = BE_fr (Belgium) , 14 = BR_pt (Brazil) , 15 = BG (Bulgaria) , 16 = CA_en (Canada) , 17 = NZ_en (New Zealand) , 18 = PL (Poland)
# 19 = RO (Romania) , 20 = CS (Czech Republic) , 21 = NO (Norway) , 22 = CH_fr (Switzerland) , 23 = SV (Sweden) , 24 = SR (Serbia)
# 25 = CN_zh (China) , 26 = JA (Japan) , 27 = GR (Greece) , 28 = LT (Lithuania) , 29 = IN_en (India) , 30 = HU (Hungary)
# 31 = AR (Argentina) , 32 = ID (Indonesia) , 33 = MY (Malaysia) , 34 = BN (Bangladesh) , 35 = MX (Mexico) , 36 = PK_en (Pakistan)
# news in this language/nation
set newslang 36

# This is for set a limit, do not post if that headline older than ** minutes
set headlinedelay 30

# How many latest news posts would like to see when you use .topnews ?
set TopNewsPosts 4

# .news on <- to enable on your #channel / .news off <- for turn this off!
setudef flag googlenews

bind pub mnf|oa ".news" news_control
bind evnt - init-server news_refresh
bind pub mnf|oa ".topnews" Google_TopNews

proc httpsregister {} {
   package require tls
   if {[package vcompare [package present tls] 1.7] > 0 } {
      ::http::register https 443 [list ::tls::socket -autoservername 1]
   } else {
      ::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
   }
}



proc httpsunregister {} {
   ::http::unregister https
}

proc Google_TopNews {nick uhost hand chan arg} {
   if {![channel get $chan googlenews]} { return 0 }
   set doc [dom parse [getit [langSel]]]
   set root [$doc documentElement]
   set i 0
   foreach id [$root selectNodes "/rss/channel/item"] {
      set desc [[$id selectNodes "description"] text]
      set Date [[$id selectNodes "pubDate"] text]
      set newsurl [[$id selectNodes "link"] text]
      set newstime [lsort -integer -decreasing -index end [clock scan $Date]]
      set news "[dom_trim $desc] [news_tiny [getRealLink [dom_trim $newsurl]]] ([duration [expr {[clock seconds] - $newstime}]] ago.)"
      if {$i == $::TopNewsPosts} break
      news_print $chan "[htmlparse::mapEscapes $news]"
      incr i
   }
   $doc delete
}

proc langSel {} {
   switch -exact -- $::newslang {
      1 { set url {us&hl=en&gl=US} }
      2 { set url {tr_tr&hl=tr&gl=TR} }
      3 { set url {fr&hl=fr&gl=FR} }
      4 { set url {de&hl=de&gl=DE} }
      5 { set url {uk&hl=en-GB&gl=GB} }
      6 { set url {ru_ru&hl=ru&gl=RU} }
      7 { set url {it&hl=it&gl=IT} }
      8 { set url {nl_nl&hl=nl&gl=NL} }
      9 { set url {au&hl=en-AU&gl=AU} }
      10 { set url {pt-PT_pt&hl=pt-PT&gl=PT} }
      11 { set url {ar_me&hl=ar&gl=ME} }
      12 { set url {de_at&hl=de-AT&gl=AT} }
      13 { set url {fr_be&hl=fr&gl=BE} }
      14 { set url {pt-BR_br&hl=pt-BR&gl=BR} }
      15 { set url {bg_bg&hl=bg&gl=BG} }
      16 { set url {ca&hl=en-CA&gl=CA} }
      17 { set url {nz&hl=en-NZ&gl=NZ} }
      18 { set url {pl_pl&hl=pl&gl=PL} }
      19 { set url {ro_ro&hl=ro&gl=RO} }
      20 { set url {cs_cz&hl=cs&gl=CZ} }
      21 { set url {no_no&hl=no&gl=NO} }
      22 { set url {fr_ch&hl=fr-CH&gl=CH} }
      23 { set url {sv_se&hl=sv&gl=SE} }
      24 { set url {sr_rs&hl=sr&gl=RS} }
      25 { set url {cn&hl=zh-CN&gl=CN} }
      26 { set url {jp&hl=ja&gl=JP} }
      27 { set url {el_gr&hl=el&gl=GR} }
      28 { set url {lt_lt&hl=lt&gl=LT} }
      29 { set url {in&hl=en-IN&gl=IN} }
      30 { set url {hu_hu&hl=hu&gl=HU} }
      31 { set url {es_ar&hl=es-419&gl=AR} }
      32 { set url {id_id&hl=id&gl=ID} }
      33 { set url {en_my&hl=en-MY&gl=MY} }
      34 { set url {bn_bd&hl=bn&gl=BD} }
      35 { set url {es_mx&hl=es-419&gl=MX} }
      36 { set url {en_pk&hl=en&gl=PK} }
      default { set url {us&hl=en&gl=US} }
   }
   return ${::googlelink}?ned=$url
}

proc news_refresh type {
   foreach chan [channels] newsbind [binds time] {
      if {([lsearch -exact [channel info $chan] "+googlenews"] != "-1") && ![string match "*Google:News*" $newsbind]} {
         bind time - "*" Google:News
         return 1
      }
   }
}

proc news_control {nick uhost hand chan text} {
   switch -nocase -- [lindex [split $text] 0] {
      "on" { if {[channel get $chan googlenews]} {
            puthelp "privmsg $chan :News already running @ $chan"
         } {
            bind time - "*" Google:News
            channel set $chan +googlenews
            puthelp "privmsg $chan :News now enabled @ $chan"
         }
      }
      "off" { if {![channel get $chan googlenews]} {
            puthelp "privmsg $chan :News already disabled @ $chan"
         } {
            unbind time - "*" Google:News
            channel set $chan -googlenews
            puthelp "privmsg $chan :News now stopped @ $chan"
         }
      }
      default { puthelp "privmsg $chan :Usage: $::lastbind <on/off>" }
   }
   return 0
}

proc getit url {
   ::httpsregister
   if {[catch {set token [http::geturl $url -binary 1 -timeout 15000]} error]} {
      putcmdlog "[string map [list \n " "] $error]"
     ::httpsunregister
      return 0
   } elseif {[string match *[http::ncode $token]* "307|303|302|301"]} {
      upvar #0 $token state
      if {[dict exists $state(meta) Location]} {
         set newurl [dict get $state(meta) Location]
         ::http::cleanup $token
         if {[catch {set newtok [http::geturl $newurl -binary 1 -timeout 15000]} err]} {
            putcmdlog "[string map [list \n " "] $err]"
         ::httpsunregister
            return 0
         } elseif {[http::status $newtok] eq "ok" && [http::ncode $newtok] == "200"} {
            set data [http::data $newtok]
            ::http::cleanup $newtok
         } else {
            putcmdlog "[http::status $newtok] - [http::code $newtok]"
            ::http::cleanup $newtok
         }
      }
      ::http::cleanup $token
   } elseif {[http::status $token] eq "ok" && [http::ncode $token] == "200"} {
      set data [http::data $token]
      ::http::cleanup $token
   } else {
      putcmdlog "[http::status $token] - [http::code $token]"
      ::http::cleanup $token
   }
   ::httpsunregister
   if {[info exists data]} {
      return [encoding convertfrom utf-8 $data]
   }
}

proc newsdom {} {
   set document [dom parse [getit [langSel]]]
   set root [$document documentElement]
   foreach id [$root selectNodes "/rss/channel/item"] {
      set description [[$id selectNodes "description"] text]
      set pubDate [[$id selectNodes "pubDate"] text]
      set newsurl [[$id selectNodes "link"] text]
      lappend news "[dom_trim $description] | [dom_trim $newsurl] | [clock scan [dom_trim $pubDate]]"
   }
   $document delete
   set listnews [lindex [lsort -integer -decreasing -index end $news] 0]
   return [join [htmlparse::mapEscapes $listnews]]
}

proc news_print {where what} {
   regexp {^(.*?)(http(?:s|)://[^\s]+)(.*?)$} $what - res links _
   set output [textutil::split::splitn $what $::newsmax]
   if {[string match *${links}* $output]} {
      lmap newsout $output { puthelp "privmsg $where :$newsout" }
   } else {
      lmap newsout [textutil::split::splitn $what [string length $res]] { puthelp "privmsg $where :$newsout" }
   }
}

proc dom_trim str {
   regsub -all -nocase {(?:<strong>|</strong>|<b>|</b>)} $str \002 str
   regsub -all -- {<font color="#6f6f6f">(.*?)</font>} $str "(\00304\\1\003)" str
   set str [string map [list &lt\; \u003c &gt\; \u003e &nbsp\; \u0020 \" \u0027] $str]
   regsub -all -- "<.+?>" $str { } str
   regsub -all -- {\s+} $str \u0020 str
   set str [string map {"View Full coverage on Google News" ""} $str]
   return [string trim $str]
}

proc news_tiny link {
   set tinyurl [getit http://tinyurl.com/api-create.php?[http::formatQuery url $link]]
   if {[info exists tinyurl] && [string length $tinyurl]} {
      return $tinyurl
   } else {
      return $link
   }
}

proc getRealLink RealURL {
   ::httpsregister
   set TokLink [http::geturl [string trim $RealURL]]
   upvar #0 $TokLink state
   set RealLink [dict get $state(meta) Location]
   ::http::cleanup $TokLink
   ::httpsunregister
   if {[info exists RealLink] && [string length $RealLink]} {
      return $RealLink
   } {
      return $RealURL
   }
}

proc Google:News args {
   foreach chan [channels] {
      if {[channel get $chan googlenews]} {
         set news [newsdom]
         set newsdesc [lindex [split $news |] 0]
         set newslink [getRealLink [lindex [split $news |] end-1]]
         set newstime [string trim [lindex [split $news |] end]]
         #scan $newsdesc {%[^(]} headline
         if {(![string match *$newslink* $::oldnews] && [expr {([clock seconds] - $newstime) < ($::headlinedelay * 60)}]) || ![llength $::oldnews]} {
            if {$::tinyurl < "1" || ![string length $::tinyurl]} {
               news_print $chan "$newsdesc : $newslink ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            } else {
               news_print $chan "$newsdesc : [news_tiny [string trim $newslink]] ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            }
            set ::oldnews "$newsdesc $newslink"
         }
      }
   }
   return 0
}

putlog "ok..."
j
jaxson
Voice
Posts: 9
Joined: Fri Dec 31, 2021 4:30 am

Move set ::oldnews "$newsdesc $newslink"

Post by jaxson »

Move this line out of the foreach loop:

set ::oldnews "$newsdesc $newslink"

Like this:

Code: Select all

proc Google:News args {
   foreach chan [channels] {
      if {[channel get $chan googlenews]} {
         set news [newsdom]
         set newsdesc [lindex [split $news |] 0]
         set newslink [getRealLink [lindex [split $news |] end-1]]
         set newstime [string trim [lindex [split $news |] end]]
         #scan $newsdesc {%[^(]} headline
         if {(![string match *$newslink* $::oldnews] && [expr {([clock seconds] - $newstime) < ($::headlinedelay * 60)}]) || ![llength $::oldnews]} {
            if {$::tinyurl < "1" || ![string length $::tinyurl]} {
               news_print $chan "$newsdesc : $newslink ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            } else {
               news_print $chan "$newsdesc : [news_tiny [string trim $newslink]] ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            }
         }
      }
   }
   set ::oldnews "$newsdesc $newslink"
   return 0
}

This way it spams to all channels joined and given +googlenews
j
jaxson
Voice
Posts: 9
Joined: Fri Dec 31, 2021 4:30 am

bind time change

Post by jaxson »

Also the bind time change doesn't work like that in the new eggdrop. Use bind cron like the below instead:

bind cron - "*/5 * * * *" Google:News

The above will call Google:News every five minutes.

Join #eggdrop on irc.rizon.net:6667 for further help.
j
jaxson
Voice
Posts: 9
Joined: Fri Dec 31, 2021 4:30 am

Try this one

Post by jaxson »

Code: Select all

# Google news v0.3 by nrt (01Dec2015)
# Updated GoogleNews Country links and added some more lines for redirected link support (04Jan2018) karakedi
# Updated the 'bind time' to 'bind cron' format for newer eggdrops; modified the foreach channel loop to allow for spam to all channels that are set to googlenews (01Jan2022) by jaxson

package require tdom
package require http
package require htmlparse
package require textutil::split
package require tls 1.6.4
package present Tcl 8.6

set ::oldnews [list ]

set googlelink {https://news.google.com/news/rss/headlines/section/topic/NATION}

# Length of chars in a line.
set newsmax 300

# Links shortened to tinyurl. 1 = true , 0 = false
set tinyurl 1

# 1 = US_en (U.S.A), 2 = TR (Turkey) , 3 = FR (France), 4 = DE (Germany), 5 = UK_en (U.K) , 6 = RU (Russia)
# 7 = IT (Italy) , 8 = NL (Netherlands) , 9 = AU_en (Australia) , 10 = PT (Portugal) , 11 = AR (Arabian World) , 12 = AT_de (Austria)
# 13 = BE_fr (Belgium) , 14 = BR_pt (Brazil) , 15 = BG (Bulgaria) , 16 = CA_en (Canada) , 17 = NZ_en (New Zealand) , 18 = PL (Poland)
# 19 = RO (Romania) , 20 = CS (Czech Republic) , 21 = NO (Norway) , 22 = CH_fr (Switzerland) , 23 = SV (Sweden) , 24 = SR (Serbia)
# 25 = CN_zh (China) , 26 = JA (Japan) , 27 = GR (Greece) , 28 = LT (Lithuania) , 29 = IN_en (India) , 30 = HU (Hungary)
# 31 = AR (Argentina) , 32 = ID (Indonesia) , 33 = MY (Malaysia) , 34 = BN (Bangladesh) , 35 = MX (Mexico) , 36 = PK_en (Pakistan)
# news in this language/nation
set newslang 36

# This is for set a limit, do not post if that headline older than ** minutes
set headlinedelay 30

# How many latest news posts would like to see when you use .topnews ?
set TopNewsPosts 4

# .news on <- to enable on your #channel / .news off <- for turn this off!
setudef flag googlenews

bind pub mnf|oa ".news" news_control
bind evnt - init-server news_refresh
bind pub mnf|oa ".topnews" Google_TopNews

proc httpsregister {} {
   package require tls
   if {[package vcompare [package present tls] 1.7] > 0 } {
      ::http::register https 443 [list ::tls::socket -autoservername 1]
   } else {
      ::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
   }
}



proc httpsunregister {} {
   ::http::unregister https
}

proc Google_TopNews {nick uhost hand chan arg} {
   if {![channel get $chan googlenews]} { return 0 }
   set doc [dom parse [getit [langSel]]]
   set root [$doc documentElement]
   set i 0
   foreach id [$root selectNodes "/rss/channel/item"] {
      set desc [[$id selectNodes "description"] text]
      set Date [[$id selectNodes "pubDate"] text]
      set newsurl [[$id selectNodes "link"] text]
      set newstime [lsort -integer -decreasing -index end [clock scan $Date]]
      set news "[dom_trim $desc] [news_tiny [getRealLink [dom_trim $newsurl]]] ([duration [expr {[clock seconds] - $newstime}]] ago.)"
      if {$i == $::TopNewsPosts} break
      news_print $chan "[htmlparse::mapEscapes $news]"
      incr i
   }
   $doc delete
}

proc langSel {} {
   switch -exact -- $::newslang {
      1 { set url {us&hl=en&gl=US} }
      2 { set url {tr_tr&hl=tr&gl=TR} }
      3 { set url {fr&hl=fr&gl=FR} }
      4 { set url {de&hl=de&gl=DE} }
      5 { set url {uk&hl=en-GB&gl=GB} }
      6 { set url {ru_ru&hl=ru&gl=RU} }
      7 { set url {it&hl=it&gl=IT} }
      8 { set url {nl_nl&hl=nl&gl=NL} }
      9 { set url {au&hl=en-AU&gl=AU} }
      10 { set url {pt-PT_pt&hl=pt-PT&gl=PT} }
      11 { set url {ar_me&hl=ar&gl=ME} }
      12 { set url {de_at&hl=de-AT&gl=AT} }
      13 { set url {fr_be&hl=fr&gl=BE} }
      14 { set url {pt-BR_br&hl=pt-BR&gl=BR} }
      15 { set url {bg_bg&hl=bg&gl=BG} }
      16 { set url {ca&hl=en-CA&gl=CA} }
      17 { set url {nz&hl=en-NZ&gl=NZ} }
      18 { set url {pl_pl&hl=pl&gl=PL} }
      19 { set url {ro_ro&hl=ro&gl=RO} }
      20 { set url {cs_cz&hl=cs&gl=CZ} }
      21 { set url {no_no&hl=no&gl=NO} }
      22 { set url {fr_ch&hl=fr-CH&gl=CH} }
      23 { set url {sv_se&hl=sv&gl=SE} }
      24 { set url {sr_rs&hl=sr&gl=RS} }
      25 { set url {cn&hl=zh-CN&gl=CN} }
      26 { set url {jp&hl=ja&gl=JP} }
      27 { set url {el_gr&hl=el&gl=GR} }
      28 { set url {lt_lt&hl=lt&gl=LT} }
      29 { set url {in&hl=en-IN&gl=IN} }
      30 { set url {hu_hu&hl=hu&gl=HU} }
      31 { set url {es_ar&hl=es-419&gl=AR} }
      32 { set url {id_id&hl=id&gl=ID} }
      33 { set url {en_my&hl=en-MY&gl=MY} }
      34 { set url {bn_bd&hl=bn&gl=BD} }
      35 { set url {es_mx&hl=es-419&gl=MX} }
      36 { set url {en_pk&hl=en&gl=PK} }
      default { set url {us&hl=en&gl=US} }
   }
   return ${::googlelink}?ned=$url
}

proc news_refresh type {
   foreach chan [channels] newsbind [binds time] {
      if {([lsearch -exact [channel info $chan] "+googlenews"] != "-1") && ![string match "*Google:News*" $newsbind]} {
         bind cron - "*/5 * * * *" Google:News
         return 1
      }
   }
}

proc news_control {nick uhost hand chan text} {
   switch -nocase -- [lindex [split $text] 0] {
      "on" { if {[channel get $chan googlenews]} {
            puthelp "privmsg $chan :News already running @ $chan"
         } {
				bind cron - "*/5 * * * *" Google:News
            channel set $chan +googlenews
            puthelp "privmsg $chan :News now enabled @ $chan"
         }
      }
      "off" { if {![channel get $chan googlenews]} {
            puthelp "privmsg $chan :News already disabled @ $chan"
         } {
				#unbind cron - "*/5 * * * *" Google:News
            channel set $chan -googlenews
            puthelp "privmsg $chan :News now stopped @ $chan"
         }
      }
      default { puthelp "privmsg $chan :Usage: $::lastbind <on/off>" }
   }
   return 0
}

proc getit url {
   ::httpsregister
   if {[catch {set token [http::geturl $url -binary 1 -timeout 15000]} error]} {
      putcmdlog "[string map [list \n " "] $error]"
     ::httpsunregister
      return 0
   } elseif {[string match *[http::ncode $token]* "307|303|302|301"]} {
      upvar #0 $token state
      if {[dict exists $state(meta) Location]} {
         set newurl [dict get $state(meta) Location]
         ::http::cleanup $token
         if {[catch {set newtok [http::geturl $newurl -binary 1 -timeout 15000]} err]} {
            putcmdlog "[string map [list \n " "] $err]"
         ::httpsunregister
            return 0
         } elseif {[http::status $newtok] eq "ok" && [http::ncode $newtok] == "200"} {
            set data [http::data $newtok]
            ::http::cleanup $newtok
         } else {
            putcmdlog "[http::status $newtok] - [http::code $newtok]"
            ::http::cleanup $newtok
         }
      }
      ::http::cleanup $token
   } elseif {[http::status $token] eq "ok" && [http::ncode $token] == "200"} {
      set data [http::data $token]
      ::http::cleanup $token
   } else {
      putcmdlog "[http::status $token] - [http::code $token]"
      ::http::cleanup $token
   }
   ::httpsunregister
   if {[info exists data]} {
      return [encoding convertfrom utf-8 $data]
   }
}

proc newsdom {} {
   set document [dom parse [getit [langSel]]]
   set root [$document documentElement]
   foreach id [$root selectNodes "/rss/channel/item"] {
      set description [[$id selectNodes "description"] text]
      set pubDate [[$id selectNodes "pubDate"] text]
      set newsurl [[$id selectNodes "link"] text]
      lappend news "[dom_trim $description] | [dom_trim $newsurl] | [clock scan [dom_trim $pubDate]]"
   }
   $document delete
   set listnews [lindex [lsort -integer -decreasing -index end $news] 0]
   return [join [htmlparse::mapEscapes $listnews]]
}

proc news_print {where what} {
   regexp {^(.*?)(http(?:s|)://[^\s]+)(.*?)$} $what - res links _
   set output [textutil::split::splitn $what $::newsmax]
   if {[string match *${links}* $output]} {
      lmap newsout $output { puthelp "privmsg $where :$newsout" }
   } else {
      lmap newsout [textutil::split::splitn $what [string length $res]] { puthelp "privmsg $where :$newsout" }
   }
}

proc dom_trim str {
   regsub -all -nocase {(?:<strong>|</strong>|<b>|</b>)} $str \002 str
   regsub -all -- {<font color="#6f6f6f">(.*?)</font>} $str "(\00304\\1\003)" str
   set str [string map [list &lt\; \u003c &gt\; \u003e &nbsp\; \u0020 \" \u0027] $str]
   regsub -all -- "<.+?>" $str { } str
   regsub -all -- {\s+} $str \u0020 str
   set str [string map {"View Full coverage on Google News" ""} $str]
   return [string trim $str]
}

proc news_tiny link {
   set tinyurl [getit http://tinyurl.com/api-create.php?[http::formatQuery url $link]]
   if {[info exists tinyurl] && [string length $tinyurl]} {
      return $tinyurl
   } else {
      return $link
   }
}

proc getRealLink RealURL {
   ::httpsregister
   set TokLink [http::geturl [string trim $RealURL]]
   upvar #0 $TokLink state
   set RealLink [dict get $state(meta) Location]
   ::http::cleanup $TokLink
   ::httpsunregister
   if {[info exists RealLink] && [string length $RealLink]} {
      return $RealLink
   } {
      return $RealURL
   }
}

proc Google:News {min hour day month year} {
   foreach chan [channels] {
      if {[channel get $chan googlenews]} {
         set news [newsdom]
         set newsdesc [lindex [split $news |] 0]
         set newslink [getRealLink [lindex [split $news |] end-1]]
         set newstime [string trim [lindex [split $news |] end]]
         #scan $newsdesc {%[^(]} headline
         if {(![string match *$newslink* $::oldnews] && [expr {([clock seconds] - $newstime) < ($::headlinedelay * 60)}]) || ![llength $::oldnews]} {
            if {$::tinyurl < "1" || ![string length $::tinyurl]} {
               news_print $chan "$newsdesc : $newslink ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            } else {
               news_print $chan "$newsdesc : [news_tiny [string trim $newslink]] ([duration [expr {[clock seconds] - $newstime}]] ago.)"
            }
         }
      }
   }
	set ::oldnews "$newsdesc $newslink"
   return 0
}

putlog "ok..."
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

Code: Select all

Tcl error [Google:News]: error "syntax error" at line 1 character 0
"0 <--Error-- "
Getting this error in result of above Script.
j
jaxson
Voice
Posts: 9
Joined: Fri Dec 31, 2021 4:30 am

Post by jaxson »

Do you have a special character at the first line character 0?

Goga wrote:

Code: Select all

Tcl error [Google:News]: error "syntax error" at line 1 character 0
"0 <--Error-- "
Getting this error in result of above Script.
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

jaxson : full code is above posted by you.
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Update langSel procedure to this:

Code: Select all

proc langSel {} {
	switch -exact -- $::newslang {
		1 { set url {en-US&gl=US&ceid=US:en} }
		2 { set url {tr&gl=TR&ceid=TR:tr} }
		3 { set url {fr&gl=FR&ceid=FR:fr} }
		4 { set url {de&gl=DE&ceid=DE:de} }
		5 { set url {en-GB&gl=UA&ceid=UA:uk} }
		6 { set url {ru&gl=RU&ceid=RU:ru} }
		7 { set url {it&gl=IT&ceid=IT:it} }
		8 { set url {nl&gl=NL&ceid=NL:nl} }
		9 { set url {en-AU&gl=AU&ceid=AU:en} }
		10 { set url {pt-PT&gl=PT&ceid=PT:pt-150} }
		11 { set url {ar&gl=EG&ceid=EG:ar} }
		12 { set url {de&gl=AT&ceid=AT:de} }
		13 { set url {fr&gl=BE&ceid=BE:fr} }
		14 { set url {pt-BR&gl=BR&ceid=BR:pt-419} }
		15 { set url {bg&gl=BG&ceid=BG:bg} }
		16 { set url {en-CA&gl=CA&ceid=CA:en} }
		17 { set url {en-NZ&gl=NZ&ceid=NZ:en} }
		18 { set url {pl&gl=PL&ceid=PL:pl} }
		19 { set url {ro&gl=RO&ceid=RO:ro} }
		20 { set url {cs&gl=CZ&ceid=CZ:cs} }
		21 { set url {no&gl=NO&ceid=NO:no} }
		22 { set url {fr&gl=CH&ceid=CH:fr} }
		23 { set url {sv&gl=SE&ceid=SE:sv} }
		24 { set url {sr&gl=RS&ceid=RS:sr} }
		25 { set url {zh-CN&gl=CN&ceid=CN:zh-Hans} }
		26 { set url {ja&gl=JP&ceid=JP:ja} }
		27 { set url {el&gl=GR&ceid=GR:el} }
		28 { set url {lt&gl=LT&ceid=LT:lt} }
		29 { set url {en-IN&gl=IN&ceid=IN:en} }
		30 { set url {hu&gl=HU&ceid=HU:hu} }
		31 { set url {es-419&gl=AR&ceid=AR:es-419} }
		32 { set url {id&gl=ID&ceid=ID:id} }
		33 { set url {en-MY&gl=MY&ceid=MY:en} }
		34 { set url {bn&gl=BD&ceid=BD:bn} }
		35 { set url {es-419&gl=MX&ceid=MX:es-419} }
		36 { set url {en-PK&gl=PK&ceid=PK:en} }
		default { set url {en-US&gl=US&ceid=US:en} }
	}
	return ${::googlelink}?hl=$url
}
Life iS Just a dReaM oN tHE wAy to DeaTh
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

having this error after replacing heartbroken's change.

Code: Select all

ok - HTTP/1.1 302 Found
Tcl error [Google_TopNews]: error "no element found" at line 1 character 0
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

so the problem is GoogleNews looks like forcing to redirects multiple times for each call.

But this getit procedure able to handle redirections only for once
it should be modify for follow the new link location for multiple times until to find some real news data on there.
Life iS Just a dReaM oN tHE wAy to DeaTh
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

what to do now then?
B
Bosco
Voice
Posts: 9
Joined: Mon Oct 31, 2022 10:57 pm

Post by Bosco »

i got this error

Tcl error [Google_TopNews]: invalid command name "lmap"


http://paste.tclhelp.net/?id=6vqh
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

lmap was new in tcl 8.6

Post by SpiKe^^ »

lmap was new in tcl 8.6

Update your tcl version to 8.6+ to get past this error.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply