aboutsummaryrefslogtreecommitdiff
path: root/vk2rss.lua
diff options
context:
space:
mode:
Diffstat (limited to 'vk2rss.lua')
-rwxr-xr-xvk2rss.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/vk2rss.lua b/vk2rss.lua
new file mode 100755
index 0000000..f611f40
--- /dev/null
+++ b/vk2rss.lua
@@ -0,0 +1,56 @@
+#!/usr/bin/lua
+
+local xml = require "xml"
+
+dofile( "vkfeed.lua" )
+dofile( "utils.lua" )
+
+function usage()
+ print( "usage: vk2rss <domain> [token]" )
+ os.exit(1)
+end
+
+function main()
+ local argc = table.maxn( arg )
+ if( argc < 1 ) then
+ usage()
+ end
+
+ local domain = arg[1]
+ local access_token = nil
+
+ if( argc == 2 ) then
+ access_token = arg[2]
+ end
+
+ local feedInfoJson = getFeedInfo( domain, access_token )
+ local feedInfo = parseFeedInfo( feedInfoJson )
+ local feedJson = getFeed( domain, 100, 0, access_token )
+ local feed = parseFeed( feedInfo["name"], feedJson )
+
+ if( feed == nil ) then
+ fatal( "Can't get feed from " .. domain )
+ end
+
+ local rss = { xml = 'rss', version="2.0",
+ { xml = 'channel',
+ { xml = 'title', feedInfo["name"] },
+ { xml = 'description', feedInfo["description"] },
+ { xml = 'link', feedInfo["url"] },
+ },
+ }
+
+ for key, item in ipairs( feed ) do
+ table.insert( rss[1], { xml = 'item',
+ { xml = 'title', item["title"] },
+ { xml = 'pubDate', item["date"] },
+ { xml = 'link', item["link"] },
+ { xml = 'description', item["description"] },
+ })
+ end
+
+ print( '<?xml version="1.0" encoding="utf-8"?>' )
+ print( xml.dump( rss ) )
+end
+
+main()