Heise: Fix

This commit is contained in:
Andreas Bielawski 2016-08-24 17:44:16 +02:00
parent c80d766f62
commit 4a9431ae13

View File

@ -6,9 +6,9 @@ heise.triggers = {
function heise:get_heise_article(article) function heise:get_heise_article(article)
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20content,src,strong%20from%20html%20where%20url=%22http://www.heise.de/newsticker/meldung/'..article..'.html%22%20and%20xpath=%22//div[@id=%27mitte_news%27]/article/header/h2|//div[@id=%27mitte_news%27]/article/div/p[1]/strong|//div[@id=%27mitte_news%27]/article/div/figure/img%22&format=json' local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20content,src,strong%20from%20html%20where%20url=%22http://www.heise.de/newsticker/meldung/'..article..'.html%22%20and%20xpath=%22//div[@id=%27mitte_news%27]/article/header/h2|//div[@id=%27mitte_news%27]/article/div/p[1]/strong|//div[@id=%27mitte_news%27]/article/div/figure/img%22&format=json'
local res,code = https.request(url) local res, code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).query.results local data = json.decode(res).query.results
if code ~= 200 then return "HTTP-Fehler" end
local title = data.h2 local title = data.h2
if data.strong then if data.strong then
@ -31,6 +31,7 @@ end
function heise:action(msg, config, matches) function heise:action(msg, config, matches)
local article = URL.escape(matches[1]) local article = URL.escape(matches[1])
local text, image_url = heise:get_heise_article(article) local text, image_url = heise:get_heise_article(article)
if not text then return end
if image_url then if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url, 'heise_teaser.jpg') local file = download_to_file(image_url, 'heise_teaser.jpg')