diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 0000000..887fb25 --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,28 @@ +name: Tests + Linting Python +on: + pull_request: + push: + branches: [main] +jobs: + lint_python: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flit + flit install -s + + - run: ./validate.sh diff --git a/.github/workflows/publish_python.yml b/.github/workflows/publish_python.yml new file mode 100644 index 0000000..064ae4b --- /dev/null +++ b/.github/workflows/publish_python.yml @@ -0,0 +1,27 @@ +name: Upload Python Package + +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.8' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flit + - name: Build and publish + env: + FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }} + FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python -m publish diff --git a/CHANGELOG.md b/CHANGELOG.md index e14b5be..f852f9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +## [0.1.0] - 2021-09-27 +### Added +- Test with fixtures +- Linter for all code +- Usage example in README + +### Fixed +- Fixed `get_variables` call +- Make sure `get_tables` returns a list + + ## [0.0.2] - 2021-09-27 ### Added - Added CHANGELOG file @@ -26,6 +37,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - `Fixed` for any bug fixes. - `Security` to invite users to upgrade in case of vulnerabilities. -[Unreleased]: https://github.com/metaodi/swissparlpy/compare/v0.0.2...HEAD +[Unreleased]: https://github.com/metaodi/swissparlpy/compare/v0.1.0...HEAD +[0.1.0]: https://github.com/metaodi/swissparlpy/compare/v0.0.2...v0.1.0 [0.0.2]: https://github.com/metaodi/swissparlpy/compare/v0.0.1...v0.0.2 [0.0.1]: https://github.com/metaodi/swissparlpy/releases/tag/v0.0.1 diff --git a/README.md b/README.md index 6659b2f..8b27bf7 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,58 @@ swissparlpy =========== Inspired by the R package [swissparl](https://github.com/zumbov2/swissparl), this module provides easy access to the data of the [OData webservice](https://ws.parlament.ch/odata.svc/) of the [Swiss parliament](https://www.parlament.ch/en). + +## Table of Contents + +* [Installation](#installation) +* [Usage](#usage) + * [ Get tables and their variables](##get-tables-and-their-variables) + * [Get data of a table](#get-data-of-a-table) +* [Release](#release) + +## Installation + +[swissparlpy is available on PyPI](https://pypi.org/project/swissparlpy/), so to install it simply use: + +``` +$ pip install swissparlpy +``` + +## Usage + +See the [`examples` directory](/examples) for more scripts. + +### Get tables and their variables + +```python +>>> import swissparlpy as spp +>>> spp.get_tables()[:5] # get first 5 tables +['MemberParty', 'Party', 'Person', 'PersonAddress', 'PersonCommunication'] +>>> spp.get_variables('Party') # get variables of table `Party` +['ID', 'Language', 'PartyNumber', 'PartyName', 'StartDate', 'EndDate', 'Modified', 'PartyAbbreviation'] +``` + +### Get data of a table + +```python +>>> import swissparlpy as spp +>>> data = spp.get_data('Canton', Language='DE') +>>> data + +>>> data.count +26 +>>> data[0] +{'ID': 2, 'Language': 'DE', 'CantonNumber': 2, 'CantonName': 'Bern', 'CantonAbbreviation': 'BE'} +>>> [d['CantonName'] for d in data] +['Bern', 'Neuenburg', 'Genf', 'Wallis', 'Uri', 'Schaffhausen', 'Jura', 'Basel-Stadt', 'St. Gallen', 'Obwalden', 'Appenzell A.-Rh.', 'Solothurn', 'Waadt', 'Zug', 'Aargau', 'Basel-Landschaft', 'Luzern', 'Thurgau', 'Freiburg', 'Appenzell I.-Rh.', 'Schwyz', 'Graubünden', 'Glarus', 'Tessin', 'Zürich', 'Nidwalden'] +``` + +## Release + +To create a new release, follow these steps (please respect [Semantic Versioning](http://semver.org/)): + +1. Adapt the version number in `swissparlpy/__init__.py` +1. Update the CHANGELOG with the version +1. Create a [pull request to merge `develop` into `main`](https://github.com/metaodi/swissparlpy/compare/main...develop?expand=1) (make sure the tests pass!) +1. Create a [new release/tag on GitHub](https://github.com/metaodi/swissparlpy/releases) (on the main branch) +1. The [publication on PyPI](https://pypi.python.org/pypi/swissparlpy) happens via [GitHub Actions](https://github.com/metaodi/swissparlpy/actions?query=workflow%3A%22Upload+Python+Package%22) on every tagged commit diff --git a/swissparlpy/__init__.py b/swissparlpy/__init__.py index f9b34c3..26a55fa 100644 --- a/swissparlpy/__init__.py +++ b/swissparlpy/__init__.py @@ -1,6 +1,6 @@ """Client for Swiss parliament API""" -__version__ = '0.0.2' +__version__ = '0.1.0' __all__ = ['client', 'errors'] from .errors import SwissParlError # noqa @@ -14,7 +14,7 @@ def get_tables(): def get_variables(table): client = SwissParlClient() - return client.get_variables() + return client.get_variables(table) def get_overview(): diff --git a/swissparlpy/client.py b/swissparlpy/client.py index 1bf669c..6e4aecd 100644 --- a/swissparlpy/client.py +++ b/swissparlpy/client.py @@ -14,7 +14,7 @@ def __init__(self, session=None): def get_tables(self): if self.cache: - return self.cache.keys() + return list(self.cache.keys()) return [es.name for es in self.client.schema.entity_sets] def get_variables(self, table):