Skip to content

Commit

Permalink
Version 0.1.0 iz.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kocisek committed Jan 31, 2022
1 parent 96fcd1b commit e0986e9
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
63 changes: 35 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
```
4 changes: 0 additions & 4 deletions ds_dphs_search.example.sh

This file was deleted.

23 changes: 0 additions & 23 deletions ds_dphs_search.sh

This file was deleted.

16 changes: 16 additions & 0 deletions iz.examples.sh
Original file line number Diff line number Diff line change
@@ -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


139 changes: 139 additions & 0 deletions iz.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0986e9

Please sign in to comment.