-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name-template: '$NEXT_PATCH_VERSION 🚘' | ||
tag-template: '$NEXT_PATCH_VERSION' | ||
template: | | ||
## What’s Changed | ||
$CHANGES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This workflows will upload a Python Package using Twine when a release is created | ||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Release Drafter | ||
|
||
on: | ||
push: | ||
# branches to consider in the event; optional, defaults to all | ||
branches: | ||
- master | ||
|
||
jobs: | ||
update_release_draft: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Drafts your next Release notes as Pull Requests are merged into "master" | ||
- uses: release-drafter/release-drafter@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pyIRNT | ||
====== | ||
|
||
.. image:: https://img.shields.io/badge/pip%20install-pyirnt-brightgreen | ||
:target: https://pypi.org/project/pyirnt | ||
.. image:: https://img.shields.io/pypi/v/pyirnt?color=green&label=version | ||
:target: https://github.com/bendikrb/pyirnt/releases | ||
.. image:: https://github.com/bendikrb/pyirnt/workflows/Test/badge.svg | ||
:target: https://github.com/bendikrb/pyirnt/actions | ||
.. image:: https://img.shields.io/github/license/bendikrb/pyirnt | ||
:target: https://github.com/bendikrb/pyirnt/blob/master/LICENSE | ||
|
||
:code:`pyirnt` is an open source client library which facilitates getting your garbage disposal schedule from `Innherred Renovasjon <https://ir.nt.no>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Init file for irnt.""" | ||
|
||
import pkg_resources # part of setuptools | ||
|
||
__version__ = pkg_resources.get_distribution("pyirnt").version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import datetime | ||
import re | ||
from urllib import parse | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
URL_CALENDAR = "https://innherredrenovasjon.no/tommeplan/{premise_id}/kalender/" | ||
URL_ADDRESS_SEARCH = "https://innherredrenovasjon.no/wp-json/ir/v1/addresses/{}" | ||
DEFAULT_HEADERS = { | ||
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0", | ||
"Cache-Control": "max-age=0", | ||
} | ||
|
||
|
||
def find_address(address: str) -> dict[str, str]: | ||
result = requests.get(URL_ADDRESS_SEARCH.format(parse.quote(address)), headers=DEFAULT_HEADERS).json() | ||
return dict((e['id'], e['address']) for e in result['data']['results']) | ||
|
||
|
||
def get_calendar(premise_id: str): | ||
response = requests.get(URL_CALENDAR.format(premise_id=premise_id), headers=DEFAULT_HEADERS) | ||
soup = BeautifulSoup(response.content, 'html.parser') | ||
|
||
year = int(re.findall(r"\d{4}", soup.find('h2', class_='article__title').get_text(strip=True)).pop()) | ||
items = [] | ||
types = [] | ||
for item in soup.findAll('div', class_='gd-calendar__list-item'): | ||
datestr = re.findall(r"(\d{2})\.(\d{2})", | ||
item.find(class_='gd-calendar__list-item-date').get_text(strip=True)).pop() | ||
dt_format = datetime.datetime.strptime(f"{year}-{datestr[1]}-{datestr[0]}", "%Y-%m-%d") | ||
entry = { | ||
"date": dt_format, | ||
"type": item.find(class_='gd-calendar__list-item-type').get_text(strip=True), | ||
} | ||
|
||
if entry['type'] not in types: | ||
types.append(entry['type']) | ||
items.append(entry) | ||
|
||
return items | ||
|
||
|
||
def get_next_pickup(premise_id: str): | ||
today = datetime.datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) | ||
n = [] | ||
for e in get_calendar(premise_id): | ||
if (e['date'] > today and len(n) == 0) or (len(n) > 0 and n[0]['date'] == e['date']): | ||
n.append(e) | ||
|
||
if len(n) == 0: | ||
return None | ||
|
||
return { | ||
"date": n[0]['date'], | ||
"types": " + ".join([e['type'] for e in n]), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[build-system] | ||
requires = ["pbr>=5.7.0", "setuptools>=36.6.0", "wheel"] | ||
build-backend = "pbr.build" | ||
build-requires = ["pbr>=5.7.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pytest | ||
pytest-cov | ||
pytest-timeout | ||
pylint | ||
flake8 | ||
pbr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
urllib3 | ||
requests~=2.26.0 | ||
setuptools~=58.5.3 | ||
beautifulsoup4~=4.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[metadata] | ||
name = irnt | ||
author = bendikrb | ||
summary = A client library to facilitate fetching garbage disposal schedules from ir.nt.no | ||
description_file = README.rst | ||
description_content_type = text/x-rst; charset=UTF-8 | ||
python_requires = >= 3.6 | ||
home_page = https://github.com/bendikrb/pyirnt | ||
project_urls = | ||
Bug Tracker = https://github.com/bendikrb/pyirnt/issues | ||
Source Code = https://github.com/bendikrb/pyirnt | ||
license = MIT | ||
classifier = | ||
Development Status :: 4 - Beta | ||
Environment :: Console | ||
Intended Audience :: Developers | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.6 | ||
Programming Language :: Python :: 3.7 | ||
Programming Language :: Python :: 3.8 | ||
keywords = | ||
api-client | ||
unofficial | ||
|
||
[files] | ||
packages = | ||
irnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Python package description.""" | ||
from setuptools import setup | ||
|
||
setup( | ||
pbr=True, | ||
) |