Posts: 71
Threads: 29
Joined: Jun 2017
Reputation:
0
Hi,
I need to read the following RSS news link https://www.20minutos.es/rss/ourense/
and represent in visualization, can someone help me?
Posts: 3
Threads: 1
Joined: Oct 2015
Reputation:
0
(19.01.2018, 08:10)Daponte Wrote: Hi,
I need to read the following RSS news link https://www.20minutos.es/rss/ourense/
and represent in visualization, can someone help me?
Hi Daponte,
this one works for us
Code: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 require( 'socket.http')
socket.http.TIMEOUT = 15
local data = socket.http.request( 'http://www.rtlnieuws.nl/service/rss/nederland/index.xml')
itemtag = false
result = {}
function starttag( parser, tag)
if tag == 'item' then
itemtag = true
table.insert( result, {})
end
currtag = tag
end
function endtag( p, tag)
if tag == 'item' then
itemtag = false
end
currtag = nil
end
function cdata( parser, text)
if itemtag and currtag then
if currtag == 'title' then
result[ # result ]. title = text
elseif currtag == 'description' then
result[ # result ]. description = text
end
end
end
lxp = require( 'lxp')
parser = lxp.new({
StartElement = starttag,
EndElement = endtag,
CharacterData = cdata,
})
ldata = [[
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.example.com/main.html</link>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
<ttl>1800</ttl>
<item>
� <title>Example entry</title>
� <description>Here is some text containing an interesting description.</description>
� <link>http://www.example.com/blog/post/1</link>
� <guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
� <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
<item>
� <title>Another example entry</title>
� <description>Here is some other text containing an interesting description.</description>
� <link>http://www.example.com/blog/post/1</link>
� <guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
� <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
</channel>
</rss>
]]
if parser: parse( data) then
else
log( 'parse failed')
end
if true == true then
grp.update( '6/1/11', ( result[ 1]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 1]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 2]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 2]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 3]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 3]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 4]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 4]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 5]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 5]. description))
end
Posts: 71
Threads: 29
Joined: Jun 2017
Reputation:
0
22.01.2018, 18:13
(This post was last modified: 22.01.2018, 18:13 by Daponte.)
(22.01.2018, 10:24)Toms thank you very much Wrote: (19.01.2018, 08:10)Daponte Wrote: Hi,
I need to read the following RSS news link https://www.20minutos.es/rss/ourense/
and represent in visualization, can someone help me?
Hi Daponte,
this one works for us
Code: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 require( 'socket.http')
socket.http.TIMEOUT = 15
local data = socket.http.request( 'http://www.rtlnieuws.nl/service/rss/nederland/index.xml')
itemtag = false
result = {}
function starttag( parser, tag)
if tag == 'item' then
itemtag = true
table.insert( result, {})
end
currtag = tag
end
function endtag( p, tag)
if tag == 'item' then
itemtag = false
end
currtag = nil
end
function cdata( parser, text)
if itemtag and currtag then
if currtag == 'title' then
result[ # result ]. title = text
elseif currtag == 'description' then
result[ # result ]. description = text
end
end
end
lxp = require( 'lxp')
parser = lxp.new({
StartElement = starttag,
EndElement = endtag,
CharacterData = cdata,
})
ldata = [[
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.example.com/main.html</link>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
<ttl>1800</ttl>
<item>
� <title>Example entry</title>
� <description>Here is some text containing an interesting description.</description>
� <link>http://www.example.com/blog/post/1</link>
� <guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
� <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
<item>
� <title>Another example entry</title>
� <description>Here is some other text containing an interesting description.</description>
� <link>http://www.example.com/blog/post/1</link>
� <guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
� <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
</channel>
</rss>
]]
if parser: parse( data) then
else
log( 'parse failed')
end
if true == true then
grp.update( '6/1/11', ( result[ 1]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 1]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 2]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 2]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 3]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 3]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 4]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 4]. description))
os.sleep( 9)
grp.update( '6/1/11', ( result[ 5]. title))
os.sleep( 4)
grp.update( '6/1/11', ( result[ 5]. description))
end
thank you very much
|