Skip to content

Instantly share code, notes, and snippets.

@flovv
Created January 17, 2016 15:09
Show Gist options
  • Save flovv/0bd4e8c105fe856cb581 to your computer and use it in GitHub Desktop.
Save flovv/0bd4e8c105fe856cb581 to your computer and use it in GitHub Desktop.
Getting Content from the "Zeit-online"
#devtools::install_github("chgrl/diezeit")
library(diezeit)
require(ggplot2)
library(plyr)
require(stringr)
require(ggthemes)
options(stringsAsFactors = FALSE)
## set key .. get your own here:
#http://developer.zeit.de/quickstart/
key="blubb"
Sys.setenv(ZEIT_KEY=key)
#############################
#helper function
dataframeFromResult <- function(l) {
l1 <- lapply(l, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
keys <- unique(unlist(lapply(l1, names)))
l2 <- lapply(l1, '[', keys)
l3 <- lapply(l2, setNames, keys)
res <- data.frame(do.call(rbind, l3))
return(res)
}
##################### function to get results!
getZeitResults <- function(term){
##limitSearch <- zeit_search("content", term, print=FALSE, limit=3)
unlimited <- zeit_search("content", term, print=FALSE, limit=1000)
dff <- dataframeFromResult(unlimited$matches)
dff$date <- as.Date(str_split_fixed(dff$release_date, "T",2)[,1])
return(dff)
}
terms <- c("data mining", "big data", "maschinelles lernen", "data scientist", "artificial intelligence", "open data")
for(i in terms){
dff <- getZeitResults(i)
dff$Term <- i
if(exists("out")){
out <- rbind(out, dff)
}
else{
out <- dff
}
}
ggplot(out, aes(date)) + geom_bar() +theme_economist() + ylab("Number of articles") + facet_wrap(~Term, scales="free")
ggplot(out, aes(Term))+ geom_bar() +theme_economist() + ylab("Overall number of articles") + xlab("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment