diff --git a/otouto/plugins/ap.lua b/otouto/plugins/ap.lua new file mode 100644 index 0000000..48fd8f0 --- /dev/null +++ b/otouto/plugins/ap.lua @@ -0,0 +1,41 @@ +local ap = {} + +ap.triggers = { + "hosted.ap.org/dynamic/stories/(.+)" +} + +function ap:get_article(article) + local url = 'http://hosted.ap.org/dynamic/stories/'..article + local res, code = http.request(url) + if code ~= 200 then return 'HTTP-Fehler '..code..' ist aufgetreten.' end + + local headline = res:match('(.-)') + if not headline then return end + + -- TODO: How to match all occurences? AP uses the same class for all paragraphs + -- but string.match only returns the first one oO + local article = unescape(utilities.trim(res:match('
(.-)
'))) + + local pic_url = res:match('