Select dois from response
This commit is contained in:
parent
26622ecefc
commit
c45dec6291
|
@ -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")
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue