1 posts
Posted 30 May 2012 - 01:10 PM
I was wondering if it is already possible to push an RSS feed to a Computer Craft monitor?
If yes, how would one do that?
Thanks in advance.
236 posts
Location
Germany
Posted 30 May 2012 - 02:55 PM
the problem is u have to read the xml feed and that is only possible with the string api and searching for the xml tags
what i did for reddit is i created a php page that reads out the json of the reddit api and returns the stuff that im interested in
so that i can read this page with lua and just split it at the points :)/>/>
see it in action at:
Click me
474 posts
Posted 30 May 2012 - 04:57 PM
the problem is u have to read the xml feed and that is only possible with the string api and searching for the xml tags
what i did for reddit is i created a php page that reads out the json of the reddit api and returns the stuff that im interested in
so that i can read this page with lua and just split it at the points :)/>/>
see it in action at:
Click me
If I were to do this I would do it all it Lua because I'm quite bad at PHP. xD
236 posts
Location
Germany
Posted 05 June 2012 - 04:28 PM
well if u want to create an xml or json decoder fore something like this:
json xml then have fun :)/>/> i like the php version more
351 posts
Posted 05 June 2012 - 04:34 PM
Well, I guess you only need to be able to read a very small subset of XML. It could be done, but it would not be pretty.
236 posts
Location
Germany
Posted 05 June 2012 - 04:54 PM
well the problem is that there are more than 1 tag named the same at the reddit xml
like the <item> tag
351 posts
Posted 05 June 2012 - 07:33 PM
Find the index of the first <item> tag, and replace everything before it with "parsed = {".
Find and replace each <item> with "{" and each </item> with "}".
Continue working your way into the structure throwing away what you dont want and reformatting what you do, until you get something like 'parsed = {{title="Yay",link="
http://yay.com"}{title="Yay2",link="http://yay2.com")}'.
Then you use
loadstring to load it in, and you can access it through tables. Easy! (kinda…)
236 posts
Location
Germany
Posted 08 June 2012 - 09:29 PM
Find the index of the first <item> tag, and replace everything before it with "parsed = {".
Find and replace each <item> with "{" and each </item> with "}".
Continue working your way into the structure throwing away what you dont want and reformatting what you do, until you get something like 'parsed = {{title="Yay",link="
http://yay.com"}{title="Yay2",link="http://yay2.com")}'.
Then you use
loadstring to load it in, and you can access it through tables. Easy! (kinda…)
didnt state that its impossible but well its way easier with an php script like this :
<?php
$sub = @$_GET['page'];
if (is_string($sub) == false) {
echo "please enter A Subreddit";
}
else
{
$str =file_get_contents("http://www.reddit.com/r/".$sub.".json");
$array = json_decode($str,true);
foreach($array['data']['children'] as $child) {
$text = $child['data']['title'];
$score = $child['data']['score'];
echo $text."<br> Score: ".$score."<br>";
}
}
?>