Skip to content

Commit

Permalink
Merge pull request #6 from metaodi/develop
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
metaodi authored Sep 27, 2021
2 parents 45e3ba1 + 0bc89a6 commit 4d0a80c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 4 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/publish_python.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<swissparlpy.client.SwissParlResponse object at 0x7f8e38baa610>
>>> 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
4 changes: 2 additions & 2 deletions swissparlpy/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion swissparlpy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4d0a80c

Please sign in to comment.