aboutsummaryrefslogtreecommitdiff
path: root/vk2rss.lua
blob: f611f40fb683d58358d061d9b4bc8841effcf1c9 (plain)
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
#!/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()