-
Notifications
You must be signed in to change notification settings - Fork 10
/
atom.lua
112 lines (108 loc) · 3.86 KB
/
atom.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--
-- rss_feed.lua
-- Copyright © 2011 Omnigeek Media. All Rights Reserved.
--
-- takes a rss feed and returns you a table of stories.
--
module(..., package.seeall)
local xml = require( "xml" ).newParser()
local utility = require("utility")
function feed(filename, base)
rssFile = "index.rss"
if filename then
rssFile = filename
end
baseDir = system.CachesDirectory
if base then
baseDir = base
end
local feed = {}
local stories = {}
--print("Parsing the feed")
local myFeed = xml:loadFile(rssFile, baseDir)
--utility.print_r(myFeed)
local items = myFeed.child
-- utility.print_r(items)
local i
--print("Number of items: " .. #items)
local l = 1
for i = 1, #items do
local item = items[i]
local enclosuers = {}
local e = 1
local story = {}
--print(item.name)
if item.name == "title" then feed.title = item.value end
if item.name == "link" then feed.link = item.value end
if item.name == "description" then feed.description = item.value end
if item.name == "subtitle" then feed.subtitle = item.value end
if item.name == "id" then feed.id = item.value end
if item.name == "updated" then feed.updated = item.value end
if item.name == "rights" then feed.rights = item.value end
if item.name == "entry" then -- we have a story batman!
local entry = {}
entry = item.child
-- utility.print_r(entry)
local j
--print("Number of items: " .. #entry)
for j = 1, #item.child do
if entry[j].name == "title" then
story.title = entry[j].value
end
if entry[j].name == "link" then
story.link = entry[j].value
end
if entry[j].name == "published" then
story.pubDate = entry[j].value
end
if entry[j].name == "description" then
story.description = entry[j].value
end
if entry[j].name == "author" then
story.author = entry[j].child[1].value
end
if entry[j].name == "id" then
story.id = entry[j].value
end
-- Podcast's we have to handle differently
if entry[j].name == "content" then
-- get the story body
--[[
print(entry[j].value)
bodytag = {}
bodytag = entry[j].child
local p;
story.content_encoded = ""
for p = 1, #bodytag do
if (bodytag[p].value) then
story.content_encoded = story.content_encoded .. bodytag[p].value .. "\n\n"
end
end
]]--
story.content = entry[j].value
end
if entry[j].name == "enclosure" then
local properties = {}
properties = entry[j].properties
enclosuers[e] = properties
--utility.print_r(properties)
e = e + 1
end
end
--utility.print_r(story)
stories[l] = {}
stories[l].link = story.link
stories[l].title = story.title
stories[l].pubDate = story.pubDate
stories[l].description = story.description
stories[l].author = story.author
stories[l].guid = story.guid
stories[l].comments = story.comments
stories[l].content = story.content
stories[l].enclosures = enclosuers
l = l + 1
end
end
feed.entries = stories
return feed
end