npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extrade-cz-api

v1.2.3

Published

Data mining tool for the czech external trade statistics database.

Downloads

34

Readme

Node.js module / client for the czech external trade statistics database

Build Status Coverage Status

Parsing library (unofficial) for the following statistics database:

https://apl.czso.cz/pll/stazo/STAZO.STAZO

Logo

Install

npm install -s extrade-cz-api

API

Get the client object:

var client = require('extrade-cz-api');

All the API methods return Q promises. You can simply handle all the possible states, as follows:

client.getCountries()
   .then(function(result){
     console.log(Object.keys(result)); // prints all the country codes
   })
   .fail(function(ex) {
     console.log(ex); // prints to the error on the stdout
   })
   .fin(function() {
     console.log('done'); // will be called in both success and failure cases
   })
   .done(); // called to be sure, that we consumed all available states

Get list of available countries

client.getCountries();

Should return a object (map) code:country_name, for example:

{ AD: 'Andorra',
  AE: 'Spojené arabské emiráty',
  AF: 'Afghánistán',
  AG: 'Antigua a Barbuda',
  AI: 'Anguilla',
  AL: 'Albánie',
  AM: 'Arménie',
  ....

Note: the names are provided in czech language.

Get a list of available products

client.getProducts();

Should return a object (map) code:product_name, for example:

{ '10011100': 'Pšenice tvrdá k setí',
  '10011900': 'Pšenice tvrdá,ne:k setí',
  '10019110': 'Špalda k setí',
  '10019120': 'k setí běžné pšenice a sourži',
  '10019190': 'k setí pšenice,sourži,ne:pšenice tvrdá,špadla,obyčejná pšenice a sourž',
  '10019900': 'Pšenice špalda, ne k setí',
  '10021000': 'Žito k setí',
  ...

Note: the names are provided in czech language.

Get last date

The statistics are not always up-to-date and there is some delay. Is it possible to obtain last available date of statistics by calling

client.getLastDate();

Should return a object (map) in following format:

{ month: '04', year: '2015' }

Get units

Product's field count can be defined in several different unit types. Typically pieces, kilograms or megawatt-hour. All known units can be returned by calling

client.getUnits()

The call should return a object (map) unit_code:unit_name, for example:

{ CTM: 'Karát',
  GRM: 'Gram',
  HLT: 'Hektolitr',
  KGN: 'Kilogram čisté váhy',
  LPA: 'Litr čistého alkoholu',
  LTR: 'Litr',
  MTK: 'Čtvereční metr',
  MTQ: 'Krychlový metr',
  MTR: 'Metr',
  MWH: 'Megawatt hodina',
  ...

This mapping can be used to translate product's field unit to a human readable text.

Get statistics

client.getStats({
   monthFrom : '04',
   yearFrom :  '2014',
   monthTill : '04',
   yearTill :  '2015',
   direction : 'd',
   products :  ['87120030', '87149110', '87149130'],
   countries : ['AT', 'DE', 'GB', 'US'],
   groupBy: 'E'
});

The direction param of the criteria has two possible values

  • d means import
  • v means export

The groupBy param of the criteria has four possible values and is not mandatory

  • E default, group by defined timespan (monthFrom, yearFrom, monthTill, yearTill in criteria)
  • A group by years
  • Q group by quarters
  • M group by months

The countries and products parameters can be obtained from the getXXX methods mentioned above.

Output is in the following format:

{ period: { from: '1.4.2014', till: '30.4.2015' },
  direction: 'import',
  results:
   [ {
       period: '1.4.2014-30.4.2015'
       code: '87120030',
       name: 'Jízdní kola, bez motoru (kromě bez kuličkových ložisek)',
       country: 'AT',
       countryName: 'Rakousko',
       weight: '28113',
       price: '19908',
       unit: 'PCE',
       count: '1900' },
     {
       period: '1.4.2014-30.4.2015'
       code: '87120030',
       name: 'Jízdní kola, bez motoru (kromě bez kuličkových ložisek)',
       country: 'BD',
       countryName: 'Bangladéš',
       weight: '5127',
       price: '2185',
       unit: 'PCE',
       count: '556' },
       ....

The period in results can be eighter a timerange like '1.4.2014-30.4.2015' or identificator like '4/2015'. The meaning of the identificator depends on groupBy option in request criteria. It can be 4th month of 2015 or 4th quarter of 2015.

How it works

The library simply fills out the form on web page for you and parses results returned in the html table.

Input form

Form to be fillted out Form, to be filled out. Fields, that can be provided, are highlighted in green.

Results page

Form to be fillted out Result page, that is parsed in order to get JSON results.

Change log

1.2.0

  • Support for groupBy attribute, grouping results by months, quarters, years or the whole timespan.
  • getUnits() method added.

1.1.5

  • Initial version, basic enum and stats methods