-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
5b0ca4c
commit 4246183
Showing
17 changed files
with
8,306 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,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: " |
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,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/[email protected] | ||
with: | ||
workdir: '.' |
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,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 |
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,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/[email protected] | ||
with: | ||
# [Required] Access token with `workflow` scope. | ||
token: ${{ secrets.PAT }} | ||
pull_request_title: "ci: Update GitHub Actions to Latest 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,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/[email protected] | ||
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,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] |
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,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" | ||
] | ||
} |
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,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" | ||
} | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"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" | ||
] | ||
} |
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 |
---|---|---|
@@ -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 | ||
``` |
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,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.
Oops, something went wrong.