Coder Social home page Coder Social logo

hlidacr's Introduction

hlidacr

CRAN status R build status codecov

The goal of hlidacr is to provide access to the data published by Hlídač státu provided by their API.

Installation

You can install the package from CRAN:

install.packages("hlidacr")

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("skvrnami/hlidacr")

Besides the installation, you need access token for making API requests. The access token is available here after the registration at the Hlídač státu’s website.

Usage

The package implements functions for accessing all publicly available API endpoints as defined in the documentation of the Hlídač státu API.

The data available via the API are related to:

  • funding of political parties
  • transcriptions of parliamentary floor debates, municipal council debates and other bodies
  • contracts between public institutions and private companies
  • subsidies
  • availability of websites operated by public institutions
    etc.

Example

There are two types of datasets available at the Hlídač státu API. First, there are various collection of datasets whose list is available using get_datasets().

library(dplyr)
library(hlidacr)

# Authorization token
TOKEN <- Sys.getenv("HLIDAC_TOKEN")

datasets <- get_datasets(token = TOKEN)
str(datasets, max.level = 1)
#> List of 3
#>  $ total  : int 31
#>  $ page   : int 1
#>  $ results:'data.frame': 31 obs. of  16 variables:
head(datasets$results[,1:2], 10)
#>                          id                                           name
#> 1         ministry-invoices                        Faktury ministerstev ČR
#> 2           rozhodnuti-uohs                                Rozhodnutí UOHS
#> 3            prijemcidotaci                                Příjemci dotací
#> 4    publicchargingstations             Seznam veřejných dobíjecích stanic
#> 5   kvalifikovanidodavatele                       Kvalifikovani dodavatele
#> 6                stav-mostu                                Stav Mostů v ČR
#> 7  seznam-politickych-stran               Seznam politických stran a hnutí
#> 8                    veklep   Elektronická knihovna legislativního procesu
#> 9          stenozaznamy-psp Stenozáznamy Poslanecké sněmovny Parlamentu ČR
#> 10 tiskove-konference-vlady                    Tiskové konference vlády ČR

In general, the data are usually returned in a list with 3 elements:

  • page
  • total: total number of records
  • results: data

(Therefore, to get the data you need to iterate over the pages by specifying particular page of the results you want. However, be aware of the fact that the API returns error if the parameter page exceeds 200.)

The data from these datasets can be obtained by get_dataset_data function using dataset’s ID. For example:

ministers <- get_dataset_data("ministri", page = 1)
head(ministers$results %>% select(resort, jmeno, strana, zacatek))
#>                                 resort            jmeno   strana
#> 1                  Ministerstvo obrany Miloslav Výborný  KDU-ČSL
#> 2     Ministerstvo životního prostředí   Richard Brabec ANO 2011
#> 3       Ministerstvo zahraničních věcí        Jan Kavan     ČSSD
#> 4           Ministerstvo spravedlnosti     Pavel Blažek      ODS
#> 5                       Předseda vlády    Jiří Paroubek     ČSSD
#> 6 Ministerstvo práce a sociálních věcí  Zdeněk Škromach     ČSSD
#>                     zacatek
#> 1 1996-07-04T00:00:00+02:00
#> 2 2018-06-27T00:00:00+02:00
#> 3 1998-07-22T00:00:00+02:00
#> 4 2012-07-03T00:00:00+02:00
#> 5 2005-04-25T00:00:00+02:00
#> 6 2004-08-04T00:00:00+02:00

Second, there are specific datasets that are available via specific routes and therefore specific functions. These include datasets related to contracts between public institutions and private companies, subsidies, companies, persons and websites.

For example:

golf_subsidies <- search_subsidies("golf")
head(golf_subsidies$results %>% select(idDotace, nazevProjektu, dotaceCelkem))
#>                                       idDotace
#> 1 dotinfo-2ebb2071-8444-40be-8560-91af6e7fefa0
#> 2                         deminimis-1000229862
#> 3                         deminimis-1000411828
#> 4       eufondy-04-06-cz-04-1-05-4-1-44-2-2970
#> 5                         deminimis-1000219471
#> 6                         deminimis-1000359004
#>                                                nazevProjektu dotaceCelkem
#> 1    GOLF CLUB U Hrádečku - podnikové vzdělávání zaměstnanců            0
#> 2               Mezinárodní golfový turnaj v extrémním golfu         5000
#> 3                                           Golf pro všechny       200000
#> 4                                           Golf pro všechny       360555
#> 5                                             Golfový turnaj        30000
#> 6 Mezinárodní golfový turnaj 112 ANNIVERSARY GOLF TOURNAMENT       150000
golf_contracts <- search_contracts("golf")
head(golf_contracts$results %>% select(predmet, hodnotaBezDph))
#>                                                   predmet hodnotaBezDph
#> 1           836/OSRM/2017 smlouva o dílo - adventure golf        245000
#> 2  Smlouva o poskytování reklamních a propagačních služeb         70000
#> 3          Smlouva o dílo - výroba propagačního materiálu        105000
#> 4  Smlouva o poskytování reklamních a propagačních služeb        762000
#> 5  Smlouva o poskytování reklamních a propagačních služeb        762000
#> 6 Smlouva o poskytování reklamních a propagačních služeb         210000

In addition, you can get the text of particular contract using get_contract_text using the ID of the contract that is stored in the column id in the data.frame returned by search_contracts.

con_text <- get_contract_text(id = "9934567")
cat(substr(con_text[1], 1500, 2000))
#>  Smlouvy
#> 
#> 1.1. Prodávající se zavazuje, že Kupujícímu odevzdá za podmínek stanovených touto
#> Smlouvou golfový multisimulátor Visual Sports s golfovým trenažérem s poslední verzí
#> golfu E6 a herní konzolí s nabídkou her jako je fotbal, basketbal, hokej a další možnosti
#> pro využití spokojenosti dětí a laserovou střelnicí, vč. sportovního vybavení na fotbal,
#> hokej a basketbal, které jsou co do technických parametrů a svého příslušenství blíže
#> specifikovány v příloze č. 1 této Smlouvy (dále jen

Searching for a person is done using search_person. For instance:

babis <- search_person("Babiš")
head(babis)
#>   titulPred    jmeno prijmeni titulPo            narozeni           nameId
#> 1      <NA>   Patrik    Babiš    <NA> 1973-05-01T00:00:00     patrik-babis
#> 2              Pavel    Babiš         1975-02-20T00:00:00      pavel-babis
#> 3              Miloš    Babiš         1960-05-12T00:00:00      milos-babis
#> 4      <NA>   Patrik    Babiš    <NA> 1972-04-17T00:00:00   patrik-babis-1
#> 5      Ing.   Andrej    Babiš    <NA> 1954-09-02T00:00:00     andrej-babis
#> 6           Alexandr    Babic         1975-11-07T00:00:00 alexandr-babic-2
#>                   profile
#> 1     /osoba/patrik-babis
#> 2      /osoba/pavel-babis
#> 3      /osoba/milos-babis
#> 4   /osoba/patrik-babis-1
#> 5     /osoba/andrej-babis
#> 6 /osoba/alexandr-babic-2

get_person function provides data related to a person such as their donations to political parties, service in public and private institutions and their social media accounts. The example below shows Andrej Babiš’s donations to political parties.

ab <- get_person("andrej-babis")
head(ab$sponzoring %>% arrange(desc(castka)))
#>       typ organizace role  castka             datumOd             datumDo
#> 1 sponzor        ANO   NA 8000000 2012-01-01T00:00:00 2012-01-01T00:00:00
#> 2 sponzor        ANO   NA 2500000 2012-01-01T00:00:00 2012-01-01T00:00:00
#> 3 sponzor        ANO   NA 2500000 2012-01-01T00:00:00 2012-01-01T00:00:00
#> 4 sponzor        ANO   NA 2000000 2012-01-01T00:00:00 2012-01-01T00:00:00
#> 5 sponzor        ANO   NA 2000000 2012-01-01T00:00:00 2012-01-01T00:00:00
#> 6 sponzor        ANO   NA 2000000 2012-01-01T00:00:00 2012-01-01T00:00:00

Besides getting social media accounts for a particular person using the get_person function, you can obtain social media accounts of Czech politicians, using get_person_social. It returns a data.frame with a data.frame nested in the socialniSite variable. For instance:

twitter_insta <- get_person_social(types = c("Instagram", "Twitter"))
twitter_insta$socialniSite[2]
#> [[1]]
#>        type           id                                    url
#> 1   Twitter PatrikNacher       https://twitter.com/PatrikNacher
#> 2 Instagram nacherpatrik https://www.instagram.com/nacherpatrik

hlidacr's People

Contributors

skvrnami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

petrbouchal

hlidacr's Issues

Make more informative error messages

E.g. when parameter strana is higher than 200, the API returns Error 400 with an error message.

  • Use the message to inform user what is the problem.
  • Update the documentation to reflect that.

Snímek obrazovky 2021-08-18 v 10 29 44

`vcr::vcr_test_path` issue from vcr v1.0.0

With the latest version of vcr just up to CRAN I unfortunately caused breaking changes for some packages depending on vcr. The function vcr_test_path is the issue. The change to that function worked for some, but it apparently has broken other packages.

We have a proposed fix at ropensci/vcr#236 Can you install that fork remotes::install_github("dpprdan/vcr@fix/test_path") and see if that fixes the problem?

Declare user agent in HTTP calls

Thanks for putting this package together - this will save me reusing bits of my own hacked-together code for accessing this API.

As per https://cran.r-project.org/web/packages/httr/vignettes/api-packages.html, it would be good if the package sent a user agent string to the server as part of HTTP ({httr} calls) (the URL of this repo might be a good one).

Happy to submit a PR - though perhaps you are on it already: I was about so submit an issue/PR around the token on env vars and I see in NEWS that's already done...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.