egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GoogleNews
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Sat Nov 06, 2021 4:48 am    Post subject: GoogleNews Reply with quote

Code:
# 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 412

# 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 20

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

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 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} {
   if {[catch {set token [http::geturl $url -binary 1 -timeout 15000]} error]} {
      putcmdlog "[string map [list \n " "] $error]"
      return 0
   } elseif {[http::status $token] eq "ok" && [http::ncode $token] == "200"} {
      set data [http::data $token]
      ::http::cleanup $token
   } elseif {[string match *[http::ncode $token]* "307|303|302|301"]} {
      upvar #0 $token state
      foreach {names values} $state(meta) {
         if {[regexp -- {^Location$} $names]} {
            putlog "Redirecting to $values"
            ::http::cleanup $token
            if {[catch {set tok [http::geturl $values -binary 1 -timeout 15000]} err]} {
               putcmdlog "[string map [list \n " "] $err]"
               break
            } elseif {[http::status $tok] eq "ok" && [http::ncode $tok] == "200"} {
               set data [http::data $tok]
               ::http::cleanup $tok
            } else {
               putcmdlog "[http::status $tok] - [http::code $tok]"
               ::http::cleanup $tok
            }
         }
      }
   } else {
      putcmdlog "[http::status $token] - [http::code $token]"
      ::http::cleanup $token
   }
   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
   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 Google:News {args} {
   foreach chan [channels] {
      if {[channel get $chan googlenews]} {
         set news [newsdom]
         set newsdesc [lindex [split $news |] 0]
         set newslink [lindex [split $news |] 1]
         set newstime [lindex [split $news |] end]
         scan $newsdesc {%[^(]} headline
         if {![string match *${newslink}* $::oldnews] && ($headline ni $::oldnews)\
               && ([expr {([clock seconds] - ${newstime}) < (${::headlinedelay} * 60)}])} {
            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 $news
         }
      }
   }
   return 0
}

putlog "ok..."



Getting this ERROR: =
Code:
wrong # args: should be "tls::socket ?options? host port"
Tcl error [Google:News]: error "syntax error" at line 1 character 0
"0 <--Error-- "

I have experinced if I change the Nation 1 from to any else, It shows ERROR showed Above.
Back to top
View user's profile Send private message
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Mon Nov 08, 2021 12:53 pm    Post subject: Reply with quote



Code:
# 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 412

# 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 40

# 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

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 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 {
   if {[catch {set token [http::geturl $url -binary 1 -timeout 15000]} error]} {
      putcmdlog "[string map [list \n " "] $error]"
      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]"
            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
   }
   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 {
   set TokLink [http::geturl [string trim $RealURL]]
   upvar #0 $TokLink state
   set RealLink [dict get $state(meta) Location]
   ::http::cleanup $TokLink
   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..."

_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Tue Nov 09, 2021 3:33 am    Post subject: GoogleNews Reply with quote

heartbroken used your given TCL, But it didn't showed anything more then 1 hour or so.. and when I did,
.topnews
it showed same error:
Code:
[07:30:47] wrong # args: should be "tls::socket ?options? host port"
Tcl error [Google_TopNews]: error "syntax error" at line 1 character 0
"0 <--Error-- "
Back to top
View user's profile Send private message
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Tue Nov 09, 2021 8:17 am    Post subject: Reply with quote

This script running on my bot since yesterday morning and I've seen nothing!.. İ've tried with different language settings for hours then shared on here...
Error must be on your side!
I assume, you're using a txt editor which doesn't have Tcl support (Windows Notepad may be ?)

Syntax check: http://paste.tclhelp.net/?id=6qlu
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
BLaCkShaDoW
Op


Joined: 11 Jan 2009
Posts: 117
Location: Romania

PostPosted: Tue Nov 09, 2021 9:51 am    Post subject: Reply with quote

Update the tls package to the latest version or at least 1.7.18
_________________
BLaCkShaDoW Production @ WwW.TclScripts.Net
Back to top
View user's profile Send private message Send e-mail Visit poster's website
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Tue Nov 09, 2021 12:24 pm    Post subject: Reply with quote

Code:
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]
 }

These lines should works if his tls 1.7.x or not.
Code:
package require tls 1.6.4
should be newer than 1.6.4 ofcourse!

His error says: syntax error:
Quote:
Tcl error [Google_TopNews]: error "syntax error" at line 1 character 0
"0 <--Error-- "
so, somehow,somethings broken the code lines/syntax when he tries to copy/paste on his editor or while he tries to edit settings. and it throws that unvisible character err...

This points me that his txt editor doesn't support Tcl syntax probably...
or copy/paste failor..


or another possibility is; his bot is soo whinie and doesn't like to see bare 0 in that line! maybe his bot wants to see that 0 between quotes in there.. so;
Code:
if {[package vcompare [package present tls] 1.7] > "0"} {

instead:
Code:
if {[package vcompare [package present tls] 1.7] > 0} {
?

my bot, she doesn't care that much....
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Wed Nov 10, 2021 2:14 am    Post subject: GoogleNews Reply with quote

Your were right about
Code:
if {[package vcompare [package present tls] 1.7] > "0"} {

Now its working very fine.
Thanks Mr. heartbroken Sir Smile
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Wed Dec 01, 2021 3:59 am    Post subject: GoogleNews Reply with quote

Dear Scripters.
When I restart my BOT, It shows NEWS only ONCE, but after that it starts to show this Error, Again I restart it shows NEWS, after that again shows this Error in DCC Chat.

Code:
[07:54:00] wrong # args: should be "tls::socket ?options? host port"
Tcl error [Google:News]: error "syntax error" at line 1 character 0
"0 <--Error-- "


Actull line in tcl is.

Code:
if {[package vcompare [package present tls] 1.7] > "0" } {


I have tried with both -> 0 and -> "0"
With "0" it shows News Once. but with 0 It does nothing just ERROR.
Please help.
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Wed Dec 01, 2021 5:49 am    Post subject: Reply with quote

Imho, the trouble is that the https registration is made globally. If you have another script which uses https and unregister it after using it, this script won't work anymore.

Solution: register the https when needed (in getit and getRealLink proc).

Note that the tinyurl proc may not work as it's set to use http and not https
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Thu Dec 02, 2021 12:50 am    Post subject: Googlenews Reply with quote

Can anyone/CrazyCat tell me step by step what to do ?
Highly appriciable.
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Mon Dec 06, 2021 4:46 am    Post subject: Google NEWS Reply with quote

CrazyCat, Plesae help me in this Regard.
Thanks
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Mon Dec 06, 2021 10:32 am    Post subject: Reply with quote

Really quick modification:
Code:
# 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 412

# 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 40

# 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 {} {
   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..."


To do it clean, the script must be rewritten to have an unique proc to the the http queries
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Tue Dec 07, 2021 2:06 am    Post subject: Reply with quote

I am really Sorry to say Crazycat, that your given COde is showing same ERROR.
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Tue Dec 07, 2021 4:00 am    Post subject: Reply with quote

Small try: edit the httpsregister procedure and add the package require tls in it:
Code:
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]
   }
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Wed Dec 08, 2021 4:45 am    Post subject: Reply with quote

You are GEM of person CrazyCat, Script is working efficiently.
And all thanks to you CrazyCat.
But I need to know/change, Is it posible that TCL shows the NEWS at once on all channels it is on?
Please make it possible to you CrazyCat
Thanking already.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber