Commit 9ccca840 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

move to ExPath HTTP client

parent 9c983c68
Pipeline #130577 passed with stages
in 3 minutes and 44 seconds
xquery version "3.1";
let $urls := (xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_db_register.txt"),
xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_ndb.txt"),
xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_adb.txt"))
let $urls := ("http://www.historische-kommission-muenchen-editionen.de/beacon_db_register.txt",
"http://www.historische-kommission-muenchen-editionen.de/beacon_ndb.txt",
"http://www.historische-kommission-muenchen-editionen.de/beacon_adb.txt")
let $maps :=
for $url in $urls
let
$persist := false(),
$request-headers := (),
$beacon := httpclient:get($url, $persist, $request-headers)//httpclient:body/node()
=> xmldb:decode() => tokenize("
")
let $request := <hc:request method="get" href="{$url}" />
let $response := hc:send-request($request)
let $beacon := $response[2] => xmldb:decode() => tokenize("&#x0A;")
let $target := $beacon[starts-with(., "#TARGET:")] => substring-after(": ")
(: should return something like "http://www.deutsche-biographie.de/pnd{ID}.html#adbcontent"
: where «{ID}» is to be replaced by the GND ID :)
......
......@@ -44,19 +44,26 @@ declare function local:cache($type as xs:string, $id as xs:string) {
let $item :=
switch ($type)
case "GND" return
let $request := httpclient:get(xs:anyURI("https://d-nb.info/gnd/"||$id||"/about/rdf"), false(), ())//httpclient:body/*
let $requestEl := <hc:request method="get" href="{'https://d-nb.info/gnd/' || $id || '/about/rdf'}"/>
let $request := hc:send-request($requestEl)[2]
let $location-node := $request//geo:asWKT
return
if($location-node = () and $request//gndo:place) then
httpclient:get(xs:anyURI($request//gndo:place/string(@rdf:resource)||"/about/rdf"), false(), ())//httpclient:body//geo:asWKT
let $request2 := <hc:request method="get" href="{ $request//gndo:place/string(@rdf:resource)||"/about/rdf" }"/>
return hc:send-request($request2)[2]//geo:asWKT
else $location-node
case "OpenStreetMap:way" return
let $first-node-of-the-way :=
string(httpclient:get(xs:anyURI("http://www.openstreetmap.org/api/0.6/way/"||$id), false(), ())//httpclient:body//nd[1]/@ref)
let $request3 := <hc:request method="get" href="{ "http://www.openstreetmap.org/api/0.6/way/"||$id }"/>
return
hc:send-request($request3)[2]//nd[1]/@ref)
return
local:cache("OpenStreetMap:node", $first-node-of-the-way)
case "OpenStreetMap:node" return
httpclient:get(xs:anyURI("http://www.openstreetmap.org/api/0.6/node/"||$id), false(), ())//httpclient:body//*:node
let $request4 := <hc:request method="get" href="{ "http://www.openstreetmap.org/api/0.6/node/"||$id }"/>
return
hc:send-request($request4)[2]//*:node
default return <item timestamp="{current-dateTime()}" type="{$type}" id="{$id}"/>
let $store-in-cache := try { update insert
<item timestamp="{current-dateTime()}" type="{$type}" id="{$id}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment