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 

Script to return Title & URL of Random Sub-Reddit Post

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
neocharles
Voice


Joined: 23 Apr 2013
Posts: 34

PostPosted: Tue Apr 23, 2013 4:34 pm    Post subject: Script to return Title & URL of Random Sub-Reddit Post Reply with quote

What I am looking to be able to do is have anyone in the room type something like

Code:
!news


And it return the title of a random post, along with said URL.

Every subreddit has an rss feed available to them by adding .rss to the end of the URL
Code:
http://www.reddit.com/r/news/.rss


I imagine the easiest way would be to query the rss feed to accomplish this.


I know pretty much zero on scripting at all, so I was curious if there is something that is already written to accomplish this, or if someone would be able to help me in getting something working for this. Simple enough that I can figure out how to add additional triggers for different URLs of rss feeds?


Thanks!
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat May 18, 2013 9:24 am    Post subject: Reply with quote

This what ive comed up for what you asked
Im not that good with XML pages or tdom but it does what you've asked for (atleast from my tests). I know it can be done different, maybe an easy way but thats how ive managed to make it with my knowledge.

The command !news works for everything if you want to change that to a particular acces post here and ill modify the script for you.

So it gets a random title and its link from that RSS page and displays it on the main channel.

Code:
bind PUB - !news rss:info

package require http
package require tdom

proc erepublik:info {nick uhost hand chan arg} {
   global {my-ip} news

   set l1 ""
   set l2 ""

   ## ++ INFO
   set token [http::config -useragent Mozilla]
   set token [http::geturl "http://www.reddit.com/r/news/.rss"]
   set data [::http::data $token]
   ::http::cleanup $token

   set XML $data

   set doc [dom parse $XML]
   set root [$doc documentElement]

   foreach node [$root getElementsByTagName "title"] { if {![string match -nocase "news" $node]} { lappend l1 "[$node asText]" } }
   foreach node [$root getElementsByTagName "link"] { if {$node != "http://www.reddit.com/r/news/"} { lappend l2 "[$node asText]" } }

   set nr 0
   foreach n $l1 { incr nr }

   set nr [rand $nr]

   putserv "PRIVMSG $chan :Title: \00304[lindex $l1 $nr] --> \00312[lindex $l2 $nr]"
}


PS: Not proud of this code
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
neocharles
Voice


Joined: 23 Apr 2013
Posts: 34

PostPosted: Sat May 25, 2013 12:00 pm    Post subject: Reply with quote

I haven't tired it yet, but had a few questions...

Is this storing the information in a 'database' of sorts for what is in the rss feed? (I'd probably suggest for anyone to use the /r/subreddit-name/new/.rss instead of the top for more variety...)

And if it is, how often is it updating that? Just on the trigger? If I trigger 5 times in a row, is it different stuff?


Also, I have quite a few subreddits I'd like to toy around with this with ... if it's not too much trouble, would you be able to show me how to do different ones with the script? Or multiple ones, etc?
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat May 25, 2013 2:35 pm    Post subject: Reply with quote

It doesnt stores anything and at every trigger request it will display a different or the same as the last info. And to add more rss pages to this script i dont know if its the same XML version (maybe it will work) but i dont know
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
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