Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-zippenfenig committed Oct 17, 2023
1 parent 5b0ca4c commit 4246183
Show file tree
Hide file tree
Showing 17 changed files with 8,306 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
reviewers:
- dciborow
allow:
- dependency-type: direct
- dependency-type: indirect
commit-message:
prefix: "fix: "
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
reviewers:
- dciborow
allow:
- dependency-type: direct
- dependency-type: indirect
commit-message:
prefix: "fix: "
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "13:00"
commit-message:
prefix: "fix: "
15 changes: 15 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Python CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [created]
workflow_dispatch:

jobs:
validation:
uses: microsoft/action-python/.github/workflows/validation.yml@0.7.2
with:
workdir: '.'
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release

#on:
# push:
# branches:
# - main

on:
workflow_dispatch:

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install semantic-release
run: npm install
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_PASSWORD }}
run: npx semantic-release
25 changes: 25 additions & 0 deletions .github/workflows/schedule-update-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: GitHub Actions Version Updater

# Controls when the action will run.
on:
workflow_dispatch:
schedule:
# Automatically run on every Sunday
- cron: '0 0 * * 0'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.PAT }}

- name: Run GitHub Actions Version Updater
uses: saadmk11/github-actions-version-updater@v0.8.1
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.PAT }}
pull_request_title: "ci: Update GitHub Actions to Latest Version"
17 changes: 17 additions & 0 deletions .github/workflows/semantic-pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Semantic PR Check"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60 changes: 60 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["-a", "from __future__ import annotations"]

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/hadialqattan/pycln
rev: v1.2.5
hooks:
- id: pycln
args: [--config=pyproject.toml]
stages: [manual]

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-log-warn
- id: python-no-eval
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/mgedmin/check-manifest
rev: "0.47"
hooks:
- id: check-manifest
stages: [manual]
46 changes: 46 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"branches": [
"main"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "build",
"section": "Dependencies and Other Build Updates",
"hidden": false
}
]
}
}
],
"@semantic-release/git",
"@semantic-release/github",
"semantic-release-pypi"
]
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTEST_ADDOPTS": "--no-cov -n0 --dist no"
}
}
]
}
29 changes: 29 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"git.autofetch": true,
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.formatting.provider": "black",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"pylint.args": [
"--rcfile=pyproject.toml"
],
"black-formatter.args": [
"--config=pyproject.toml"
],
"flake8.args": [
"--toml-config=pyproject.toml"
],
"isort.args": [
"--settings-path=pyproject.toml"
]
}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# python-requests
Open-Meteo Python Library using `requests`




### Development

```bash
pip3 install .
pip3 install ".[test]"
pip3 install pytest-xdist
pre-commit install

black .
flake8
bandit -r openmeteo_requests/
pylint openmeteo_requests/
python3 -m pytest tests/
pre-commit run --all-files
```
76 changes: 76 additions & 0 deletions openmeteo_requests/Client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Sync client"""

from __future__ import annotations

from typing import TypeVar

import requests
from openmeteo_sdk.AirQualityApiResponse import AirQualityApiResponse
from openmeteo_sdk.ClimateApiResponse import ClimateApiResponse
from openmeteo_sdk.EnsembleApiResponse import EnsembleApiResponse
from openmeteo_sdk.FloodApiResponse import FloodApiResponse
from openmeteo_sdk.MarineApiResponse import MarineApiResponse
from openmeteo_sdk.WeatherApiResponse import WeatherApiResponse

T = TypeVar("T")


class OpenMeteoRequests(Exception):
"""Open Meteo Error"""


def decode_messages(cls: type[T], data: bytes) -> list[T]:
"""Decode byte to an array of FlatBuffers messages"""
messages = []
total = len(data)
pos = int(0)
while pos < total:
length = int.from_bytes(data[pos : pos + 4], byteorder="little")
message = cls.GetRootAs(data, pos + 4)
messages.append(message)
pos += length + 4
return messages


class Client:
"""Open Meteo Client SYNC"""

def __init__(self, session: requests.Session | None = None):
self.session = session or requests.Session()

def _get(self, cls: type[T], url: str, params: any) -> list[T]:
response = self.session.get(url, params=params)
if response.status_code in [400, 429]:
response_body = response.json()
raise OpenMeteoRequests(response_body)

response.raise_for_status()
return decode_messages(cls, response.content)

def weather_api(self, url: str, params: any) -> list[WeatherApiResponse]:
"""Get and decode as weather api"""
return self._get(WeatherApiResponse, url, params)

def ensemble_api(self, url: str, params: any) -> list[EnsembleApiResponse]:
"""Get and decode as ensemble api"""
return self._get(EnsembleApiResponse, url, params)

def flood_api(self, url: str, params: any) -> list[FloodApiResponse]:
"""Get and decode as flood api"""
return self._get(FloodApiResponse, url, params)

def air_quality_api(self, url: str, params: any) -> list[AirQualityApiResponse]:
"""Get and decode as air quality api"""
return self._get(AirQualityApiResponse, url, params)

def climate_api(self, url: str, params: any) -> list[ClimateApiResponse]:
"""Get and decode as climate api"""
return self._get(ClimateApiResponse, url, params)

def marine_api(self, url: str, params: any) -> list[MarineApiResponse]:
"""Get and decode as marine api"""
return self._get(MarineApiResponse, url, params)

def __del__(self):
"""cleanup"""
self.session.close()
Empty file added openmeteo_requests/__init__.py
Empty file.
Loading

0 comments on commit 4246183

Please sign in to comment.