Comparison

mod_pubsub_feed/mod_pubsub_feed.lua @ 279:aa0df3db4901

mod_pubsub_feed: Wrap entry in a item element.
author Kim Alvefur <zash@zash.se>
date Sat, 27 Nov 2010 20:44:22 +0100
parent 278:653c1826739e
child 299:801066bf5793
comparison
equal deleted inserted replaced
278:653c1826739e 279:aa0df3db4901
4 -- Component "pubsub.example.com" "pubsub" 4 -- Component "pubsub.example.com" "pubsub"
5 -- modules_enabled = { 5 -- modules_enabled = {
6 -- "pubsub_feed"; 6 -- "pubsub_feed";
7 -- } 7 -- }
8 -- feeds = { -- node -> url 8 -- feeds = { -- node -> url
9 -- telecomix = "https://status.telecomix.org/api/statuses/public_timeline.atom"; 9 -- prosody_blog = "http://blog.prosody.im/feed/atom.xml";
10 -- } 10 -- }
11 -- feed_pull_interval = 20 -- minutes 11 -- feed_pull_interval = 20 -- minutes
12 12
13 local modules = hosts[module.host].modules; 13 local modules = hosts[module.host].modules;
14 if not modules.pubsub then 14 if not modules.pubsub then
15 module:log("warn", "Pubsub needs to be loaded on this host"); 15 module:log("warn", "Pubsub needs to be loaded on this host");
16 end 16 end
17 local add_task = require "util.timer".add_task; 17 local add_task = require "util.timer".add_task;
18 local date, time = os.date, os.time; 18 local date, time = os.date, os.time;
19 local dt_parse = require "util.datetime".parse; 19 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime;
20 local http = require "net.http"; 20 local http = require "net.http";
21 local parse_feed = require "feeds".feed_from_string; 21 local parse_feed = require "feeds".feed_from_string;
22 local st = require "util.stanza";
22 23
23 local config = module:get_option("feeds") or { 24 local config = module:get_option("feeds") or {
24 planet_jabber = "http://planet.jabber.org/atom.xml"; 25 planet_jabber = "http://planet.jabber.org/atom.xml";
25 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; 26 prosody_blog = "http://blog.prosody.im/feed/atom.xml";
26 }; 27 };
66 67
67 local timestamp = e_published or e_updated or nil; 68 local timestamp = e_published or e_updated or nil;
68 module:log("debug", "timestamp is %s, item.last_update is %s", tostring(timestamp), tostring(item.last_update)); 69 module:log("debug", "timestamp is %s, item.last_update is %s", tostring(timestamp), tostring(item.last_update));
69 if not timestamp or not item.last_update or timestamp > item.last_update then 70 if not timestamp or not item.last_update or timestamp > item.last_update then
70 local id = entry:get_child("id"); 71 local id = entry:get_child("id");
71 id = id[1] or item.url.."#"..timestamp; 72 id = id[1] or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up
73 local item = st.stanza("item", { id = id }):add_child(entry);
74
72 module:log("debug", "publishing to %s, id %s", node, id); 75 module:log("debug", "publishing to %s, id %s", node, id);
73 modules.pubsub.service:publish(node, actor, id, entry) 76 modules.pubsub.service:publish(node, actor, id, item)
74 end 77 end
75 end 78 end
76 end); 79 end);
77 end 80 end
78 return refresh_interval; 81 return refresh_interval;