| View previous topic :: View next topic |
| Author |
Message |
neocharles Voice
Joined: 23 Apr 2013 Posts: 34
|
Posted: Tue Apr 23, 2013 4:34 pm Post subject: Script to return Title & URL of Random Sub-Reddit Post |
|
|
What I am looking to be able to do is have anyone in the room type something like
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 |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat May 18, 2013 9:24 am Post subject: |
|
|
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 |
|
 |
neocharles Voice
Joined: 23 Apr 2013 Posts: 34
|
Posted: Sat May 25, 2013 12:00 pm Post subject: |
|
|
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 |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat May 25, 2013 2:35 pm Post subject: |
|
|
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 |
|
 |
|