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.

xml reader

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
g
gamer12
Voice
Posts: 10
Joined: Tue Aug 14, 2012 6:58 pm

xml reader

Post by gamer12 »

Need a script which can read a XML page and displays on channel whenever its updated. The feed can be accessed once per / 25 seconds.

<info>Anything between these tags</info>

http://goo.gl/NbHrS -> is the xml page's link.

Any help will be appreciated.

PS: tried every script which is on egghelp.org's tcl section.

Thanks.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

see code posted below...
Last edited by speechles on Fri Jul 05, 2013 6:37 pm, edited 3 times in total.
g
gamer12
Voice
Posts: 10
Joined: Tue Aug 14, 2012 6:58 pm

thank you bro!

Post by gamer12 »

It is doing what I wanted ;D

the only problem is, it keeps on displaying the same item again and again. It should display only when its changed :o

any help in it will be appreciated.

Thanks again speechless. Im speechless ;D
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: thank you bro!

Post by speechles »

gamer12 wrote:It is doing what I wanted ;D

the only problem is, it keeps on displaying the same item again and again. It should display only when its changed :o

any help in it will be appreciated.

Thanks again speechless. Im speechless ;D
Yeah, that was my bad. It is this line:

Code: Select all

if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 1] - ::news::ary(last) } 
Which that lindex position is based off: {junk info link}
The order they occur in your site, info then link, not link then info.

link is lindex position 2 now, not 1 anymore...

the correct line is:

Code: Select all

if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 2] - ::news::ary(last) }
I've corrected this line in my code posted above if you just want to copy/replace the entire thing as well.

Also, take special note: The script uses the flag +nopubnews to TURN OFF output in channels. It will automatically work in every channel all at once. This is the opposite of how it usually works with chanset, you normally set a flag for channels you want it working in. This is how the original request asked the flag to operate and this behavior was never changed. Just keep it in mind.
g
gamer12
Voice
Posts: 10
Joined: Tue Aug 14, 2012 6:58 pm

hello agai

Post by gamer12 »

I tried changing the line as we as copying the above script whole.

It is still repeating the 1st entry.

Code: Select all

set ary(bind_time) "*" ; # every minute 

   # url to news page 
   set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml 

   # parsing regex used to gather news 
   set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>} 

   # how to snip last-id from the url mask 
   set ary(snip_lastid) {^(.*?)$} 

   # max amount of news items to announce 
   set ary(max_bot) 1

   # max amount of news items for users 
   set ary(max_user) 1 
with these settings.

Ive restarted the bot to.

thanks.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Try this

Code: Select all

# Puh Rum Pum Pum Pum

# This script will announce news just like an rss script
# as well as allowing users to type commands and see
# the latest news via notice as well. Fully configurable.
# Enjoy, and may the force be with you.... always....

# speechles was here :P

package require http
setudef flag nopubnews

namespace eval news {
	# config - make your changes here
	# trigger character
	set ary(pref) "!"

	# command used to reply to user
	# this can be a list of space delimited commands
	set ary(commands) "events"

	# amount user can issue before throttle
	set ary(throttle) 2

	# throttle time
	set ary(throttle_time) 30

	# time to announce new news items
	# this can be a list of space delimited time binds.
	# the one you wish to use for bind_time uncommented.
	# set ary(bind_time) "00* 15* 30* 45*" ; # every 15 minutes
	# set ary(bind_time) "00* 30*" ; # every 30 minutes
	# set ary(bind_time) "00*" ; # every 60 minutes exactly on the hour
	set ary(bind_time) "*" ; # every minute

	# url to news page
	set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml

	# parsing regex used to gather news
	set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>}

	# how to snip last-id from the url mask
	set ary(snip_lastid) {^(.*?)$}

	# max amount of news items to announce
	set ary(max_bot) 1

	# max amount of news items for users
	set ary(max_user) 1

	# display format for news messages, variables are: %info and %url
	# these can be used and will be replaced with actual values, newline (\n) will
	# let you span multiple lines if you wish. If something is too long it will
	# be cut off, be aware of this... use colors, bold, but remember to \escape any
	# special tcl characters.
	set ary(display_format) "\[\002eRepublik\002\] \002\0033\Event:\002\ %info. - \002\0032\Link:\002\ %url"

	# script version
	set ary(version) "2.3"
}

# binds
foreach bind [split $::news::ary(commands)] {
	bind pub -|- "$::news::ary(pref)$bind" ::news::pub_
	bind msg -|- "$::news::ary(pref)$bind" ::news::msg_
}
foreach bind [split $::news::ary(bind_time)] {
	bind time - $bind ::news::magic_
}
bind time - ?0* ::news::throttleclean_

namespace eval news {
	# main - time bind - magic
	proc magic_ {args} {
		news_ $::botnick [getchanhost $::botnick] $::botnick "all" "magic"
	}

	# main - msg bind - notice
	proc msg_ {nick uhost hand arg} {
		news_ $nick $uhost $hand $nick "notice"
	}

	# main - pub bind - privmsg
	proc pub_ {nick uhost hand chan arg} {
		if {[channel get $chan nopubnews]} { return }
		news_ $nick $uhost $hand $chan "privmsg"
	}

	# sub - give news
	proc news_ {nick uhost hand chan arg} {
		global existss
		if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::news::ary(throttle_time)]} {
			putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
		}
		set a "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
		set t [::http::config -useragent $a]
		catch { set t [::http::geturl $::news::ary(page) -timeout 30000] } error
		# error condition 1, socket error or other general error
		if {![string match -nocase "::http::*" $error] && ![isbotnick $nick]} {
			putserv "$arg $chan :[string totitle [string map {"\n" " | "} $error]] \( $::news::ary(page) \)"
			return
		}
		# error condition 2, http error
		if {![string equal -nocase [::http::status $t] "ok"] && ![isbotnick $nick]} {
			putserv "$arg $chan :[string totitle [::http::status $t]] \( $::news::ary(page) \)"
			return
		}
		set html [::http::data $t]
		::http::cleanup $t
		set casafreenews [regexp -all -inline "$::news::ary(regex)" $html]
		set c 0
		foreach {junk info link} $casafreenews {
			incr c ; set url "http://erepublik.com$link"
			if {[isbotnick $nick]} {
				if {$c > $::news::ary(max_bot)} { break }
				regexp "$::news::ary(snip_lastid)" $url - id
				if {[info exists ::news::ary(last)]} { if {$id == $::news::ary(last)} { break } }
			} elseif {$c > $::news::ary(max_user)} { break }
			set output [string map [list "%info" "[mapit_ [string map [list "<br />" ""] $info]]" "%url" "$url"] $::news::ary(display_format)]
			if {![string equal "magic" $arg]} {
				foreach line [split $output "\n"] {
					if {![info exists existss($chan,$line)]} {
						puthelp "$arg $chan :$line"

						set existss($chan,$line) "[unixtime]"

					}
				}
			} else {
				foreach ch [channels] {
					if {[channel get $ch nopubnews]} { continue }
					foreach line [split $output "\n"] {
						if {![info exists existss($ch,$line)]} {
							puthelp "privmsg $ch :$line"

							set existss($ch,$line) "[unixtime]"
						}

					}
				}
			}
			if {[string equal "magic" $arg]} { regexp "$::news::ary(snip_lastid)" [lindex $casafreenews 2] - ::news::ary(last) }
		}
	}

	# sub - map it
	proc mapit_ {t} { return [string map [list "'" "'" """ "\""] $t] }

	# Throttle Proc (slightly altered, super action missles) - Thanks to user
	# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
	proc throttle_ {id seconds} {
		if {[info exists ::news::throttle($id)]&&[lindex $::news::throttle($id) 0]>[clock seconds]} {
			set ::news::throttle($id) [list [lindex $::news::throttle($id) 0] [set value [expr {[lindex $::news::throttle($id) 1] +1}]]]
			if {$value > $::news::ary(throttle)} { set id 1 } { set id 0 }
		} {
			set ::news::throttle($id) [list [expr {[clock seconds]+$seconds}] 1]
			set id 0
		}
	}
	# sub - clean throttled users
	proc throttleclean_ {args} {
		set now [clock seconds]
		foreach {id time} [array get ::news::throttle] {
			if {[lindex $time 0]<=$now} {unset ::news::throttle($id)}
		}
	}
}
putlog "news and announce.tcl v$::news::ary(version) loaded."
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Shouldn't be there a return in the if check regarding the throttling?
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Madalin wrote:* snipped exploitable code *
I know you pace the floor looking for someone to help. Don't get me wrong. I can sense the eagerness. The feeling of needing something to do to make your tcl skills better. I dig it. You are useful. You submit scripts. Well done.

The part that gets under my skin is when someone introduces exploits into my scripts and leaves my name there and not their name claiming credit for adding the exploit. Here is where your skills will get better. Let me explain.

Code: Select all

set existss($ch,$line) "[unixtime]" 
You realize what this does, right? $line will and does contain special characters. You allow substitution within the array name. This is called an exploitable bug. Please take the time to add your name to the script when making any changes. Do not just assume that authors of open source scripts will claim credit for code you may contribute that compromises their eggdrop. Thanks....

And caesar, the return is not required. The value returned from the last command will be returned in the absense of return.
Last edited by speechles on Fri Jul 05, 2013 6:37 pm, edited 1 time in total.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

spechless trust me if i knew you talk this much i wouldnt modify the code.
gamer asked me to modify it because it didnt worked as he wanted, when i was finished i posted here because he didnt respond where we first talked and thats all.

:) its very obviously that you really need to cool down a little bit its like i tooked your girlfriend from you. You can always ignore my post as it wasnt posted for you. Next time i modify some of your 'possible' code please sue me and keep the other small talk for yourself.

PS: I really thought frustrated 'kids' like you discovered girls some time ago, i guess i was wrong.

Next time make a note somewhere "Madalin or anyone else don`t edit this or i will shoot myself' or something like this :) i would really appreciate
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# Puh Rum Pum Pum Pum

# This script will announce news just like an rss script
# as well as allowing users to type commands and see
# the latest news via notice as well. Fully configurable.
# Enjoy, and may the force be with you.... always....

# speechles was here :P

package require http
setudef flag usenews

namespace eval readxml {
   # config - make your changes here
   # trigger character
   set ary(pref) "!"

   # command used to reply to user
   # this can be a list of space delimited commands
   set ary(commands) "news"

   # amount user can issue before throttle
   set ary(throttle) 2

   # throttle time
   set ary(throttle_time) 30

   # time to announce new news items
   # this can be a list of space delimited time binds.
   # the one you wish to use for bind_time uncommented.
   # set ary(bind_time) "00* 15* 30* 45*" ; # every 15 minutes
   # set ary(bind_time) "00* 30*" ; # every 30 minutes
   # set ary(bind_time) "00*" ; # every 60 minutes exactly on the hour
   set ary(bind_time) "*" ; # every minute

   # url to news page
   set ary(page) http://travian.gamingcrazy.net/erep-api/feeds/militaryfeeds.xml

   # parsing regex used to gather news
   set ary(regex) {<info>(.*?)</info>.*?<link>(.*?)</link>}

   # how to snip last-id from the url mask
   set ary(snip_lastid) {^(.*?)$}

   # max amount of news items to announce
   set ary(max_bot) 5

   # max amount of news items for users
   set ary(max_user) 5

   # display format for news messages, variables are: %info and %url
   # these can be used and will be replaced with actual values, newline (\n) will
   # let you span multiple lines if you wish. If something is too long it will
   # be cut off, be aware of this... use colors, bold, but remember to \escape any
   # special tcl characters.
   set ary(display_format) "\[\002NEWS\002\] %url\n%info"

   # script version
   set ary(version) "2.3"
}

# binds
foreach bind [split $::readxml::ary(commands)] {
   bind pub -|- "$::readxml::ary(pref)$bind" ::readxml::pub_
   bind msg -|- "$::readxml::ary(pref)$bind" ::readxml::msg_
}
foreach bind [split $::readxml::ary(bind_time)] {
   bind time - $bind ::readxml::magic_
}
bind time - ?0* ::readxml::throttleclean_

namespace eval readxml {
   # main - time bind - magic
   proc magic_ {args} {
      news_ $::botnick [getchanhost $::botnick] $::botnick "all" "magic"
   }

   # main - msg bind - notice
   proc msg_ {nick uhost hand arg} {
      news_ $nick $uhost $hand $nick "notice"
   }

   # main - pub bind - privmsg
   proc pub_ {nick uhost hand chan arg} {
      if {![channel get $chan usenews]} { return }
      news_ $nick $uhost $hand $chan "privmsg"
   }

   # sub - give news
   proc news_ {nick uhost hand chan arg} {
      if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} {
         putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
         # that missing return mentioned by caeser in this thread
         # now makes its official appearance below...
         return
      }
      set a "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
      set t [::http::config -useragent $a]
      catch { set t [::http::geturl $::readxml::ary(page) -timeout 30000] } error
      # error condition 1, socket error or other general error
      if {![string match -nocase "::http::*" $error] && ![isbotnick $nick]} {
         putserv "$arg $chan :[string totitle [string map {"\n" " | "} $error]] \( $::readxml::ary(page) \)"
         return
      }
      # error condition 2, http error
      if {![string equal -nocase [::http::status $t] "ok"] && ![isbotnick $nick]} {
         putserv "$arg $chan :[string totitle [::http::status $t]] \( $::readxml::ary(page) \)"
         return
      }
      set html [::http::data $t]
      ::http::cleanup $t
      set casafreenews [regexp -all -inline "$::readxml::ary(regex)" $html]
      set c 0
      foreach {junk info link} $casafreenews {
         incr c ; set url "http://travian.gamin.ds$link"
         if {[isbotnick $nick]} {
            if {$c > $::readxml::ary(max_bot)} { break }
            if {[info exists ::readxml::ary(last)]} { if {$url == $::readxml::ary(last)} { break } }
         } elseif {$c > $::readxml::ary(max_user)} { break }
         set output [string map [list "%info" "[mapit_ [string map [list "<br />" ""] $info]]" "%url" "$url"] $::readxml::ary(display_format)]
         if {![string equal "magic" $arg]} {
            foreach line [split $output "\n"] { puthelp "$arg $chan :$line" }
         } else {
            foreach ch [channels] {
               if {![channel get $ch usenews]} { continue }
               foreach line [split $output "\n"] { puthelp "privmsg $ch :$line" }
            }
         }
      }
      if {[string equal "magic" $arg]} { set ::readxml::ary(last) "http://travian.gamin.ds[lindex $casafreenews 2]" }
   }

   # sub - map it
   proc mapit_ {t} { return [string map [list "'" "'" """ "\""] $t] }

   # Throttle Proc (slightly altered, super action missles) - Thanks to user
   # see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
   proc throttle_ {id seconds} {
      if {[info exists ::readxml::throttle($id)]&&[lindex $::readxml::throttle($id) 0]>[clock seconds]} {
         set ::readxml::throttle($id) [list [lindex $::readxml::throttle($id) 0] [set value [expr {[lindex $::readxml::throttle($id) 1] +1}]]]
         if {$value > $::readxml::ary(throttle)} { set id 1 } { set id 0 }
      } {
         set ::readxml::throttle($id) [list [expr {[clock seconds]+$seconds}] 1]
         set id 0
      }
   }
   # sub - clean throttled users
   proc throttleclean_ {args} {
      set now [clock seconds]
      foreach {id time} [array get ::readxml::throttle] {
         if {[lindex $time 0]<=$now} {unset ::readxml::throttle($id)}
      }
   }
}

putlog "news and announce.tcl v$::readxml::ary(version) loaded."
<guy1> wtf.. that speechles guy is a dick
<guy2> tell me about it
<speechles> SCREW YOU GUYS!
Just remember how to spell my name, speechles
there isn't two s at the end, efnet ate the last one.

Also.. To use the script I made it conform to normal:
.chanset #chan +usenews enables in channel

Tested and this time, we have a winnar. puh rum pum pum pum.

EDIT: go figure, didn't test _every_ part of the script. Somewhere gravity caused a rift in space time, or something to do with higgs boson particles, caused a missing "return" in the script which would cause the throttle to announce but never become effective. This is now corrected thanks caeser (did i get the name right this time? hint: yes because i looked and cheated)
Last edited by speechles on Sat Jul 06, 2013 5:15 am, edited 1 time in total.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I was referring to:

Code: Select all

      if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} {
         putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
      } 
Isn't the whole idea to STOP the execution of the rest of the code if it's throttled? Maybe I'm missing something.

Anyway, you two mind your manners. We aren't here in any sort of competition, so there's no 1st place, second or whatever. We all want to learn new stuff and expand our skills. Don't we?

Regarding the $line exploit, chill, the line is taken from that xml page, so I doubt they will start exploiting their own users that want to fetch some info. :lol: Good point anyway. 8)

As for spelling names, speechles you are no stranger to this either. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

caesar wrote:I was referring to:

Code: Select all

      if {![isbotnick $nick] && [throttle_ $uhost,$chan,news $::readxml::ary(throttle_time)]} {
         putserv "$arg $chan :$nick, you have been Throttled! You're going too fast and making my head spin!"
      } 
Isn't the whole idea to STOP the execution of the rest of the code if it's throttled? Maybe I'm missing something.
You are indeed correct. It needs a return or the evaluation needs to contain } else { # != throttled/botnick }

Not sure where that missing return went. Maybe my dog ate it? Odd, since I don't have a dog.
caesar wrote:Anyway, you two mind your manners. We aren't here in any sort of competition, so there's no 1st place, second or whatever. We all want to learn new stuff and expand our skills. Don't we?
It's more about it than that. It's about alterations, and who gets the credit/blame for the bugs those alterations cause. In this case I would get the complaints for it when it wasn't my doing. Right? Maybe? Bueller? Bueller?
caesar wrote:Regarding the $line exploit, chill, the line is taken from that xml page, so I doubt they will start exploiting their own users that want to fetch some info. :lol: Good point anyway. 8)
I always prefer to wear shoes when walking outdoors. Don't you? Never know when you are going to step on a nail. Using that $line thing is akin to going barefoot. All I'm saying... heh
caesar wrote:As for spelling names, speechles you are no stranger to this either. :)
Dude, your name is hard to remember. Is it AE or EA? Without looking I have a 50/50 chance of getting your name right.. :D


BTW, Note to anyone still reading this thread... Here's some juicy parts I didn't want to leave out...

Just fyi ... I misspelt the damn variable name, casafreenews, which contains the list of info/links to spew. When it stored the last-url it had seen, I had it working like so, [lindex $casefreenews 2]. Wrong.. BZZT! It starts with casA not casE. This effectively was creating the scenario where it wasn't able to remember the last url it had seen. The reason it was still failing to work I just thought I'd throw out there for legacy sake. Someone in the future, perhaps 30 years from now might be reading this. To that future person reading this, you're still using eggdrop? seriously? What damn version is it up to? I know you cant answer me. But answer somewhere in this thread just to bump it up to the top after you've read this. People in the future would get a kick seeing someone predict their bumping of this very post in advance even if not accurately only figuratively, eh.. :P

Also, super-secret-news, something most will likely scoff at as rumor, but expect an incith-google update in the very near future. Very near meaning this weekend... stay tuned to these forums for updates. Follow us through twitter at http://twitter.com/suqmuhnutz for real-time announcements and special VIP access to on-the-spot bug-fixes and feature requests... ;)

source:https://twitter.com/suqmuhnutz/status/353446861207633920
Post Reply