#' Отримайте короткий опис політики
#'
#' @param id Вектор, який містить id депутата (має складатись щонайменше з одного елементу).
#'
#' @param key Ваш персональний ключ API, отриманий на rada4you.org
#'
#' @return Датафрейм, що складається з семи змінних для кожного депутата: id, mp, party, electorate, rebellions, attended, possible
#'
#' @export
mps_info <- function(id, key) {
depbioall <- data.frame()
for(i in id) {
request <- httr::GET(url = "https://rada4you.org/",
path = paste0("api/v1/people/", i, ".json"),
query = list(key = key))
if(httr::status_code(request) != 200) {
stop(
message(paste('Помилка. Код відповіді сервера: '), httr::status_code(request)))
} else {
response <- httr::content(request, as = 'text')
json <- jsonlite::fromJSON(response)
print(request)
depbio <- data.frame(
id = json$id,
mp = paste(json$latest_member$name$first, json$latest_member$name$last),
party = json$latest_member$party,
electorate = json$latest_member$electorate,
rebellions = json$rebellions,
attended = json$votes_attended,
possible = json$votes_possible,
stringsAsFactors = F)
depbioall <- rbind.data.frame(depbioall, depbio)
library(magrittr)
depbioall$party <- depbioall$party %>%
stringr::str_replace_all(pattern = "Фракція Політичної партії \"НАРОДНИЙ ФРОНТ\"",
replacement = 'Народний фронт') %>%
stringr::str_replace_all(pattern = "Фракція ПАРТІЇ \"БЛОК ПЕТРА ПОРОШЕНКА\"",
replacement = 'Блок Петра Порошенка') %>%
stringr::str_replace_all(pattern = "Фракція політичної партії \"Всеукраїнське об'єднання \"Батьківщина\" у Верховній Раді України",
replacement = 'ВО "Батьківщина"') %>%
stringr::str_replace_all(pattern = "Фракція Радикальної партії Олега Ляшка",
replacement = 'Радикальна партія Олега Ляшка') %>%
stringr::str_replace_all(pattern = "Група \"Воля народу\"",
replacement = 'група "Воля народу"') %>%
stringr::str_replace_all(pattern = "Фракція Політичної партії \"Об'єднання \"САМОПОМІЧ\"" ,
replacement = 'Об’єднання "Самопоміч"') %>%
stringr::str_replace_all(pattern = "Група \"Партія \"Відродження\"" ,
replacement = 'група "Відродження"') %>%
stringr::str_replace_all(pattern = "Фракція Політичної партії \"Опозиційний блок\" у Верховній Раді України восьмого скликання",
replacement = 'Опозиційний блок')
Sys.sleep(1)
detach(package:magrittr)
}
}
return(depbioall)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.