-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from chrbknudsen/main
gammelt materiale bevaret
- Loading branch information
Showing
29 changed files
with
1,547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
^_pkgdown\.yml$ | ||
^docs$ | ||
^pkgdown$ | ||
^skrammel$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Package: KBAPI | ||
Type: Package | ||
Title: What the Package Does (Title Case) | ||
Version: 0.1.0 | ||
Author: Who wrote it | ||
Maintainer: The package maintainer <yourself@somewhere.net> | ||
Description: More about what it does (maybe more than one line) | ||
Use four spaces when indenting paragraphs within the Description. | ||
License: What license is it under? | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.2.0 | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 | ||
Imports: | ||
dplyr, | ||
magrittr, | ||
rvest |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(get_authors) | ||
export(get_categories) | ||
export(get_collections) | ||
export(get_editions) | ||
export(get_genres) | ||
export(get_subcollections) | ||
importFrom(magrittr,"%>%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#' Get authors | ||
#' | ||
#' Retrieves a list of available authors in Text Collections | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_authors() | ||
#' | ||
#' @export | ||
|
||
get_authors <- function(){ | ||
test <- jsonlite::read_json("https://api.kb.dk/data/rest/api/text?q=cat_ssi:author+AND+type_ssi:work&wt=json&start=0&rows=75&defType=edismax", | ||
simplifyVector = T) | ||
test$response$docs$inverted_name_title_ssi | ||
} | ||
|
||
# det er ikke givet at det er den format der skal bruges til at søge. | ||
# Så her er nogle alternativer | ||
# test$response$docs[[2]]$work_title_tesim | ||
# test$response$docs[[2]]$sort_title_ssi | ||
# test$response$docs[[2]]$inverted_name_title_ssi | ||
|
||
|
||
|
||
# Nedenstående skal placeres i et internt datasæt, og hentes som alternativ | ||
# til at trække data fra apien. (for det tager tid!) | ||
fall_back <- c("Palladius, Peder" , | ||
"Paludan-Müller, Frederik", | ||
"Ploug, Carl", | ||
"Møller, Poul Martin", | ||
"Richardt, Christian", | ||
"Saxo", | ||
"Schack, Hans Egede", | ||
"Schandorph, Sophus", | ||
"Sibbern, Frederik Christian", | ||
"Skjoldborg, Johan", | ||
"Skram, Erik", | ||
"Michaëlis, Sophus", | ||
"Staffeldt, Schack", | ||
"Steffens, Henrich", | ||
"Sthen, Hans Christensen", | ||
"Stub, Ambrosius", | ||
"Stuckenberg, Viggo", | ||
"Thomissøn, Hans", | ||
"Topsøe, Vilhelm", | ||
"Wessel, Johan Herman", | ||
"Wied, Gustav", | ||
"Winther, Christian", | ||
"Worm, Jacob", | ||
"Aakjær, Jeppe", | ||
"Aarestrup, Emil", | ||
"Ravnkilde, Adda", | ||
"Arrebo, Anders", | ||
"Bagger, Carl", | ||
"Baggesen, Jens", | ||
"Bang, Herman", | ||
"Bergsøe, Vilhelm", | ||
"Blicher, Steen Steensen", | ||
"Bødtcher, Ludvig", | ||
"Bording, Anders", | ||
"Brahe, Tycho", | ||
"Brandes, Georg", | ||
"Brorson, Hans Adolph", | ||
"Chievitz, Poul", | ||
"Claussen, Sophus", | ||
"Dalgas, Ernesto", | ||
"Drachmann, Holger", | ||
"Brandes, Edvard", | ||
"Ewald, Johannes", | ||
"Falster, Christian", | ||
"Fibiger, Mathilde", | ||
"Heiberg, Johanne Luise", | ||
"Gjellerup, Karl", | ||
"Goldschmidt, M. A.", | ||
"Grundtvig, N. F. S.", | ||
"Gyllembourg, Thomasine", | ||
"Hauch, Carsten", | ||
"Andersen, Hans Christian", | ||
"Helie, Paulus", | ||
"Hertz, Henrik", | ||
"Hjortø, Knud", | ||
"Holberg, Ludvig", | ||
"Hostrup, Jens Christian", | ||
"Rode, Helge", | ||
"Ingemann, B. S.", | ||
"Knudsen, Jakob", | ||
"Jacobsen, Jørgen-Frantz", | ||
"Heiberg, Johan Ludvig", | ||
"Jacobsen, J. P.", | ||
"Juel-Hansen, Erna", | ||
"Kidde, Harald Henrik Sager", | ||
"Kierkegaard, Søren", | ||
"Kingo, Thomas", | ||
"Kaalund, Hans Vilhelm", | ||
"Larsen, Thøger", | ||
"Larsen, Karl", | ||
"Leonora Christina", | ||
"Lyschander, Claus Christoffersen", | ||
"Nansen, Peter", | ||
"Oehlenschläger, Adam", | ||
"Heiberg, Peter Andreas") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Get categories | ||
#' | ||
#' FIXME | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_categories() | ||
#' | ||
#' @export | ||
|
||
get_categories <- function(){ | ||
base_url <- "https://api.kb.dk/data/text" | ||
|
||
test <- rvest::read_html(base_url) | ||
|
||
res <- test |> | ||
rvest::html_element("#cat_ssi") %>% | ||
rvest::html_elements("option") %>% | ||
rvest::html_attrs() %>% | ||
unlist() | ||
unname(res[nchar(res)>0]) | ||
} | ||
|
||
# den kan nok også med fordel have en "non-live" option | ||
# og så kommer den ud som en named character vector. | ||
# det skal der nok gøres noget ved. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Get collections | ||
#' | ||
#' FIXME | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_collections() | ||
#' | ||
#' @export | ||
|
||
get_collections <- function(){ | ||
navn <- NULL | ||
base_url <- "https://api.kb.dk/data/" | ||
|
||
rvest::read_html(base_url) %>% | ||
rvest::html_elements("body .main-nav a") %>% | ||
purrr::map_dfr(~data.frame( | ||
"navn" = rvest::html_attr(., "href"), | ||
"beskrivelse" = rvest::html_text(.) | ||
)) %>% | ||
dplyr::mutate(link = paste0(base_url, navn)) | ||
} | ||
# Hvis ovenstående fejler - returner denne: | ||
# navn beskrivelse link | ||
# 1 dsfl Aerial photographs https://api.kb.dk/data/dsfl | ||
# 2 cop Digital collections https://api.kb.dk/data/cop | ||
# 3 text Text collections https://api.kb.dk/data/text | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
hent_have_data <- function(){ | ||
url <- "http://www5.kb.dk/images/billed/2010/okt/billeder/subject37894/da/?page=" | ||
data <- httr::GET(paste0(url,1), add_headers(Accept = "application/json")) %>% | ||
content(type = "text", encoding = "UTF-8") %>% | ||
fromJSON() | ||
data <- data$response | ||
sider <- data$pages$total_pages | ||
res <- list() | ||
res[[1]] <- data$docs %>% as.data.frame() | ||
for(i in 2:sider){ | ||
res[[i]] <- httr::GET(paste0(url,i), add_headers(Accept = "application/json")) %>% | ||
content(type = "text", encoding = "UTF-8") %>% fromJSON() %>% | ||
.$response %>% | ||
.$docs %>% | ||
as.data.frame() | ||
} | ||
bind_rows(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#' Get editions | ||
#' | ||
#' FIXME | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_editions() | ||
#' | ||
#' @export | ||
|
||
|
||
get_editions <- function(){ | ||
jsonlite::read_json("https://api.kb.dk/data/rest/api/editions", | ||
simplifyVector = T) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' Get genres | ||
#' | ||
#' FIXME | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_genres() | ||
#' | ||
#' @export | ||
|
||
|
||
|
||
get_genres <- function(){ | ||
base_url <- "https://api.kb.dk/data/text" | ||
|
||
test <- rvest::read_html(base_url) | ||
|
||
res <- test |> | ||
rvest::html_element("#genre_ssi") |> | ||
rvest::html_elements("option") |> | ||
rvest::html_attrs() |> | ||
unlist() | ||
unname(res[nchar(res)>0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Get subcollections | ||
#' | ||
#' FIXME | ||
#' | ||
#' @param live logical value indicating if list of authors should be retrieved live, or from internal data. | ||
#' | ||
#' @return None | ||
#' | ||
#' @examples | ||
#' get_subcollections() | ||
#' | ||
#' @export | ||
|
||
get_subcollections <- function(){ | ||
test <- jsonlite::read_json("https://api.kb.dk/data/rest/api/text?q=&rows=0&facet=on&facetfield=subcollection_ssi", | ||
simplifyVector = F) | ||
test <- test$facet_counts$facet_fields$subcollection_ssi | ||
test <- test[seq(1, length(test), 2)] | ||
unlist(test) | ||
|
||
|
||
# Med mindre ovenstående fejler - ellers returner: | ||
# c("adl", "gv", "tfs", "sks") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Installer httr2, hvis det ikke allerede er installeret | ||
# install.packages("httr2") | ||
|
||
# Load httr2 pakken | ||
library(httr2) | ||
|
||
# Definer API-endpointet | ||
api_url <- "http://www.kb.dk/cop/syndication/images/luftfo/2011/maj/luftfoto/subject203/" | ||
|
||
# Opret en query string med parametrene | ||
query_params <- list( | ||
bbo = "10.395490670074423,55.22227193719089,10.296785378326376,55.18994697228769", | ||
zoom = 14, | ||
lat = 55.20611273543719, | ||
lng = 10.346138024200382, | ||
page = 1, | ||
q_fritekst = "", | ||
q_stednavn = "", | ||
q_bygningsnavn = "", | ||
q_person = "", | ||
q_adresse = "", | ||
notBefore = 1920, | ||
notAfter = 1970, | ||
category = "subject203", | ||
itemType = "all", | ||
thumbnailSize = "", | ||
format = "xml" | ||
) | ||
|
||
# Send GET-anmodningen med parametre som query string | ||
response <- request(api_url) %>% | ||
req_url_query(!!!query_params) %>% | ||
req_perform() | ||
|
||
response | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#' Pipe operator | ||
#' | ||
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. | ||
#' | ||
#' @name %>% | ||
#' @rdname pipe | ||
#' @keywords internal | ||
#' @export | ||
#' @importFrom magrittr %>% | ||
#' @usage lhs \%>\% rhs | ||
#' @param lhs A value or the magrittr placeholder. | ||
#' @param rhs A function call using the magrittr semantics. | ||
#' @return The result of calling `rhs(lhs)`. | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# KB-API | ||
Code to pull data from the Royal Library API | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.