From e0986e9c7322f842296af65eb2d9012e99c2e0b6 Mon Sep 17 00:00:00 2001 From: Marcel Kocisek Date: Mon, 31 Jan 2022 15:41:48 +0100 Subject: [PATCH] Version 0.1.0 iz.sh --- .vscode/settings.json | 3 + README.md | 63 +++++++++-------- ds_dphs_search.example.sh | 4 -- ds_dphs_search.sh | 23 ------- iz.examples.sh | 16 +++++ iz.sh | 139 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 193 insertions(+), 55 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 ds_dphs_search.example.sh delete mode 100644 ds_dphs_search.sh create mode 100644 iz.examples.sh create mode 100644 iz.sh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff30c44 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.tabSize": 2 +} \ No newline at end of file diff --git a/README.md b/README.md index ce2615b..d53a649 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,44 @@ Môžeme využiť súbor s názvom **key** do parent priečinku s ./config súbo ## Súbory -### ds_dphs_search.sh +### iz.sh -Vyhladavanie zo zoznamu subjektov registrovaných k DPH +Vyhľadávanie v REST API pre OpenData FS Information Lists API. + +Zoznam všetkých dostupných zoznamov (information lists): + +``` bash +./iz.sh -al | jq +``` + +Detail o zozname Zoznam platiteľov DPH s číslom účtu správcu dane vedeným pre daňový subjekt. + +```bash +./iz.sh -l ds_dph_oud | jq +``` + +Result: + +- každý zoznam je identifkovaný podľa atribútu *slug* +- atribút *searchable* definuje vyhľadávacuie stĺpce + +```json +{ + "name": "Zoznam platiteľov DPH s číslom účtu správcu dane vedeným pre daňový subjekt", + "slug": "ds_dph_oud", + "url": "https://report.financnasprava.sk/ds_dph_oud.zip", + "update_date": "2022-01-31 05:05:02", + "searchable": [ + "ic_dph" + ] +} +``` + +Vyhľadávanie v jednotlivých zoznamoch podľa atribútu *slug=ds_dphs* a stĺpca *ic_dph* s hodnotou *SK2020317068*. V zozname platitelov DPH nájdeme spoločnosť s ICDPH *SK2020317068* ``` bash -# Najdeme v zozname platitelov DPH vsetkych podla ic_dph SK2020317068 -# popis všetkých argumentov je v súbore! -ds_dphs_search.sh SK2020317068 | jq +# Nájdeme v zozname platitelov DPH všetkých podľa ic_dph SK2020317068 +./iz.sh -ds ds_dphs -s SK2020317068 -c ic_dph | jq ``` Result @@ -47,26 +77,3 @@ Result ] } ``` - -``` bash -# Njademe v zozanme platitelov DPH konkretne zaznamy podla ic_dph SK2020317068 -# popis všetkých argumentov je v súbore! -ds_dphs_search.sh SK2020317068 | jq '.data[]' -``` - -Result - -```json -{ - "ic_dph": "SK2020317068", - "ico": "31333532", - "nazov_ds": "ESET, spol. s r.o.", - "obec": "Bratislava - mestská časť Petržalka", - "psc": "85101", - "ulica_cislo": "Einsteinova 24", - "stat": "Slovensko", - "druh_reg_dph": "§4", - "datum_reg": "11.10.2000", - "datum_zmeny_druhu_reg": null -} -``` diff --git a/ds_dphs_search.example.sh b/ds_dphs_search.example.sh deleted file mode 100644 index c3b2515..0000000 --- a/ds_dphs_search.example.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -# ziskanie objekt pre eset -. ./ds_dphs_search.sh SK2020317068 | jq '.data[]' \ No newline at end of file diff --git a/ds_dphs_search.sh b/ds_dphs_search.sh deleted file mode 100644 index 421db55..0000000 --- a/ds_dphs_search.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# Zoznam subjektov registrovaných k DPH -# prvy argument hladana hodnota (defaultna hodnota je 1) -# druhy argument page -# treti argument stlpec (defaultna hodnota je ic_dph) -# -# Example: ./ds_dphs_search.sh SK2020317068 - -set -e - -. ./config.sh - -_SEARCH=$1 -_PAGE=${2:-1} -_COLUMN=${3:-"ic_dph"} - -./generator/generated/iz/client.sh \ ---host https://iz.opendata.financnasprava.sk/api/data \ -dataSlugSearchGet \ -'key:${OAFS_KEY}' \ -slug=ds_dphs page=${_PAGE} column=${_COLUMN} search=${_SEARCH} - diff --git a/iz.examples.sh b/iz.examples.sh new file mode 100644 index 0000000..eaabe57 --- /dev/null +++ b/iz.examples.sh @@ -0,0 +1,16 @@ +# Ziskanie dostupnych zoznamov z APi +./iz.sh -al | jq + +# Ziskanie detailu o zozname ds_dph_oud +./iz.sh -l ds_dph_oud | jq + +# Ziskanie vsetkych platitelov DPH na strane 1 (defaultna hodnota) +./iz.sh -d ds_dphs | jq + +# Ziskanie stranu 2 z platitelov DPH +./iz.sh -d ds_dphs -p 2 | jq + +# Najdeme v zozname platitelov DPH vsetkych podla ic_dph SK2020317068 +./iz.sh -ds ds_dphs -s SK2020317068 -c ic_dph | jq + + diff --git a/iz.sh b/iz.sh new file mode 100644 index 0000000..b60b9cf --- /dev/null +++ b/iz.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash + +set -e + +print_help(){ + ./generator/generated/iz/client.sh --about + echo -e "-al/--available-lists - All lists in API" + echo -e "-l/--list [slug] - Detail of list based on string slug" + echo -e "-d/--data [slug] - Get data based on slug" + echo -e "-ds/--data-search [slug] - Searching in list based on slug" + echo -e "-p/--page [page] - Page in large data (default is 1)" + echo -e "-c/--column [column] - Searchable column" + echo -e "-s/--search [term] - Searching term in selected -c/--column" +} + +. ./config.sh + +get_slug=false +get_page=false +get_column=false +get_search=false + +for param in "$@"; do + + case $OPERATION in + "listsSlugGet") + SLUG=$param + continue + ;; + *) + ;; + esac + + if [[ "$get_slug" = true ]]; then + SLUG=$param + get_slug=false + continue + fi + + if [[ "$get_page" = true ]]; then + PAGE=$param + get_page=false + continue + fi + + if [[ "$get_search" = true ]]; then + SEARCH=$param + get_search=false + continue + fi + + if [[ "$get_column" = true ]]; then + COLUMN=$param + get_column=false + continue + fi + + case $param in + -al|--available-lists) + OPERATION="listsGet" + break + ;; + -l|--list) + OPERATION="listsSlugGet" + ;; + -d|--data) + OPERATION="dataSlugGet" + get_slug=true + ;; + -ds|--data-search) + OPERATION="dataSlugSearchGet" + get_slug=true + ;; + -s|--search) + get_search=true + ;; + -c|--column) + get_column=true + ;; + -p|--page) + get_page=true + ;; + -h|--help) + print_help + exit 0 + ;; + -*|--*) + echo "ERROR: Unknown param $param" + exit 1 + ;; + *) + ;; + esac +done + +# Check if user provided host name +if [[ -z "$OPERATION" ]]; then + echo "ERROR: Operation not supported, not enough arguments" + exit 1 +fi + +PARAMS="" + +case $OPERATION in + "listsSlugGet") + if [[ -z "$SLUG" ]]; then + echo "ERROR: Missing parameter" + exit 1 + fi + PARAMS="${PARAMS} slug=${SLUG}" + ;; + "dataSlugGet") + if [[ -z "$SLUG" ]]; then + echo "ERROR: Missing parameter" + exit 1 + fi + PARAMS="${PARAMS} slug=${SLUG} page=${PAGE:-1}" + ;; + "dataSlugSearchGet") + if [[ -z "$SLUG" ]]; then + echo "ERROR: Missing parameter" + exit 1 + fi + if [[ -z "$COLUMN" ]]; then + echo "ERROR: Missing parameter column" + exit 1 + fi + PARAMS="${PARAMS} slug=${SLUG} page=${PAGE:-1} column=${COLUMN} search=${SEARCH}" + ;; + *) + ;; +esac + +./generator/generated/iz/client.sh \ +--host https://iz.opendata.financnasprava.sk/api/data \ +${OPERATION} \ +'key:${OAFS_KEY}' \ +$PARAMS +