Skip to content

Commit

Permalink
Merge pull request #1 from lnx85/library-deploy
Browse files Browse the repository at this point in the history
Library deploy
  • Loading branch information
lnx85 authored Jul 3, 2024
2 parents 52b4ed2 + c7e859e commit 69fbb57
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 31 deletions.
11 changes: 3 additions & 8 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
"files.trimTrailingWhitespace": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.autoSearchPaths": false,
"python.analysis.extraPaths": [
"/home/vscode/.local/lib/python3.12/"
],
"python.analysis.extraPaths": ["/home/vscode/.local/lib/python3.12/"],
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
Expand Down Expand Up @@ -58,8 +56,5 @@
"postStartCommand": "pip install -r requirements_dev.txt && pre-commit install && pip install -e .",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"runArgs": [
"-e",
"GIT_EDITOR=code --wait"
]
}
"runArgs": ["-e", "GIT_EDITOR=code --wait"]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ cover/
# Ignore Vscode files
.vscode

# Ignore MacOS files
.DS_Store

*.egg-info/
.noseids
nosetests.xml
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# Client Library for Osservaprezzi

## Installation

If you have a recent version of Python 3, you should be able to
do `pip install osservaprezzi` to get the most recently released version of
this.

## Usage

You are welcome to try using this as a python library for other efforts.
A simple usage might go something like this:

```python
import aiohttp
import asyncio
import logging

from osservaprezzi.client import Osservaprezzi
from osservaprezzi.models import GPSCoordinates


async def main():
async with aiohttp.ClientSession() as session:
logging.basicConfig(level=logging.DEBUG)
client = Osservaprezzi(session)

# brands list
brands = await client.get_brands()
for brand in brands:
print(brand.name)

# fuels list
fuels = await client.get_fuels()
for fuel in fuels:
print(fuel)

# stations list 5 km near 45.541553,10.211802
location = GPSCoordinates(latitude=45.541553, longitude=10.211802)
stations = await client.get_stations(location, radius=5)
for station in stations:
print(station.name)

# station details
station = await client.get_station(47997)
print(station.name)


if __name__ == '__main__':
asyncio.run(main())
```

## Thanks

My heartfelt thanks to:

- All the users who have given useful feedback and contributed code!
Binary file added osservaprezzi/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion osservaprezzi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
PATH_API_ZONES = "search/zone"
PATH_API_SERVICE_AREA = "registry/servicearea/%d"
REQUEST_HEADERS = {
# pylint: disable-next=line-too-long
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0",
"Origin": "https://carburanti.mise.gov.it",
"Host": "carburanti.mise.gov.it",
Expand Down
4 changes: 3 additions & 1 deletion osservaprezzi/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Helpers definition."""

from __future__ import annotations

from datetime import datetime
from typing import Any

Expand Down Expand Up @@ -37,7 +39,7 @@ def fuel_from_json(json: dict[str, Any]) -> Fuel:
return Fuel(
id=json.get("id", 0),
price=json.get("price", 0),
name=json.get("name", ""),
name=json.get("name", json.get("description", "")),
fuel_id=json.get("fuelId", 0),
is_self=json.get("isSelf", False),
insert_date=datetime.fromisoformat(json["insertDate"])
Expand Down
169 changes: 169 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
[build-system]
requires = ["setuptools>=60",
"setuptools-scm>=8.0"]
build-backend = "setuptools.build_meta"

[project]
name = "osservaprezzi"
license = {text = "GPL-3.0"}
description = "Python library for Osservaprezzi Carburanti "
readme = "README.md"
authors = [
{name = "Lorenzo Monaco", email = "[email protected]"}
]
keywords = ["osservaprezzi", "carburanti", "mise"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
]
requires-python = ">=3.12.0"
dynamic = ["dependencies", "version"]

[project.urls]
"Homepage" = "https://github.com/lnx85/osservaprezzi.py"
"Source Code" = "https://github.com/lnx85/osservaprezzi.py"
"Bug Reports" = "https://github.com/lnx85/osservaprezzi.py/issues"

[tool.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools.packages.find]
include = ["osservaprezzi*"]

[tool.setuptools_scm]
[tool.black]
target-version = ['py311']
safe = true



[tool.ruff.lint]
select = [
"ALL",
]

ignore = [
"ANN101", # Self... explanatory
"ANN102", # Cls... explanatory
"ANN401", # Opinioated warning on disallowing dynamically typed expressions
"D203", # Conflicts with other rules
"D213", # Conflicts with other rules
"EM101", # raw-string-in-exception

"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"E501", # line too long

"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable


# Conflicts with the Ruff formatter
"COM812",
"ISC001",

# Remove later
"TD", # Todos
"A", # bultins
"DTZ", # use tz need to test it first
"TRY", # tryceratops
"FIX002", # Line contains TODO, consider resolving the issue
"BLE001", # Do not catch blind exception: `Exception`

]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false


[tool.ruff.lint.isort]
combine-as-imports = true
force-sort-within-sections = true
known-first-party = [
"osservaprezzi",
]
required-imports = ["from __future__ import annotations"]


[tool.ruff.lint.per-file-ignores]
"tests/**" = [
"D100", # Missing docstring in public module
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"N802", # Function name {name} should be lowercase
"N816", # Variable {name} in global scope should not be mixedCase
"PLR0913", # Too many arguments in function definition
"S101", # Use of assert detected
"SLF001", # Private member accessed: {access}
"T201", # print found
]


[tool.ruff.lint.mccabe]
max-complexity = 12

[tool.ruff.lint.pylint]
max-args = 7


[tool.pylint.MAIN]
py-version = "3.12"
ignore = [
"tests",
]
fail-on = [
"I",
]

[tool.pylint.BASIC]
good-names= ["i","j","k","ex","_","T","x","y","id","tg"]

[tool.pylint."MESSAGES CONTROL"]
# Reasons disabled:
# format - handled by black
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
# abstract-class-little-used - prevents from setting right foundation
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
# abstract-method - with intro of async there are always methods missing
# inconsistent-return-statements - doesn't handle raise
# too-many-ancestors - it's too strict.
# wrong-import-order - isort guards this
# ---
# Pylint CodeStyle plugin
# consider-using-namedtuple-or-dataclass - too opinionated
# consider-using-assignment-expr - decision to use := better left to devs
disable = [
"format",
"cyclic-import",
"duplicate-code",
"too-many-arguments",
"too-many-instance-attributes",
"too-many-locals",
"too-many-ancestors",
"too-few-public-methods",
"invalid-name",
]
enable = [
"useless-suppression",
"use-symbolic-message-instead",
]

[tool.pylint.REPORTS]
score = false


[tool.pylint.FORMAT]
expected-line-ending-format = "LF"

[tool.pylint.EXCEPTIONS]
overgeneral-exceptions = [
"builtins.BaseException",
"builtins.Exception",
]
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r requirements.txt
-r requirements_test.txt
ruff==0.5.0
ruff==0.5.0
36 changes: 18 additions & 18 deletions tests/__snapshots__/test_fuels.ambr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# serializer version: 1
# name: test_fuels[response0][fuels]
list([
Fuel(id='1-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='1-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='1-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-x', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-1', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-0', price=0, name='', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='1-x', price=0, name='Benzina', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='1-1', price=0, name='Benzina (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='1-0', price=0, name='Benzina (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-x', price=0, name='Gasolio', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-1', price=0, name='Gasolio (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='2-0', price=0, name='Gasolio (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-x', price=0, name='Metano', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-1', price=0, name='Metano (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='3-0', price=0, name='Metano (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-x', price=0, name='GPL', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-1', price=0, name='GPL (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='4-0', price=0, name='GPL (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-x', price=0, name='L-GNC', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-1', price=0, name='L-GNC (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='323-0', price=0, name='L-GNC (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-x', price=0, name='GNL', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-1', price=0, name='GNL (Self)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
Fuel(id='324-0', price=0, name='GNL (Servito)', fuel_id=0, is_self=False, insert_date=None, validity_date=None),
])
# ---
# name: test_fuels[response1][fuels]
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""Common fixtures for the Ecovacs tests."""

from collections.abc import AsyncGenerator, Generator
from __future__ import annotations

import logging
from typing import Any
from typing import TYPE_CHECKING, Any
from unittest.mock import patch

from aiohttp import ClientSession
import pytest

from osservaprezzi.client import Osservaprezzi

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Generator


@pytest.fixture
async def client() -> AsyncGenerator[Osservaprezzi, None]:
Expand Down

0 comments on commit 69fbb57

Please sign in to comment.