From c45dec6291019b9423544638dfa4c6f89a3d7541 Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Sun, 18 Feb 2024 19:32:16 +0100 Subject: [PATCH] Select dois from response --- lua/sourcer/init.lua | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lua/sourcer/init.lua b/lua/sourcer/init.lua index 0329be6..9c68459 100644 --- a/lua/sourcer/init.lua +++ b/lua/sourcer/init.lua @@ -11,12 +11,33 @@ function M.lookup() -- Execute the curl command and capture its output local handle = io.popen(command) - local response = handle:read("*a") - handle:close() + local response = "" + if handle ~= nil then + response = handle:read("*a") + handle:close() + else + response = "" + end + + -- select doi links from response + local b = 1 + local doi_links = {} + while true do + local x, y = response:find("//doi/[a-zA-Z]+/10.[0-9]+/[0-9.]+/gm", b, false) + + -- stop if no further occurrences are found + if x == nil or y == nil then + break + end + + -- save substring to doi_links + doi_links:insert(response:sub(x, y)) + b = y + end print("Keywords: " .. keywords) print("URL: " .. url) - print("Response: " .. response) + print("links: " .. doi_links) end return M