Skip to content

Commit

Permalink
Fix created value be none (#8)
Browse files Browse the repository at this point in the history
* Datetime can be NONE now

* Update documentation

* Fix pytest code for 100% codecov
  • Loading branch information
klaasnicolaas committed Aug 3, 2022
1 parent 45c46a3 commit 1a487ea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pip install liege

You can read the following datasets with this package:

- Disabled parking spaces / Stationnement PMR (950 locations)
- Garages / Les parkings voitures hors voirie (10 locations)
- [Disabled parking spaces / Stationnement PMR][disabled_parking] (952 locations)
- [Garages / Les parkings voitures hors voirie][garages] (26 locations)

<details>
<summary>Click here to get more details</summary>
Expand Down Expand Up @@ -193,6 +193,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[api]: https://opendata.liege.be/explore
[disabled_parking]: https://opendata.liege.be/explore/dataset/stationnement-pmr
[garages]: https://opendata.liege.be/explore/dataset/parkings-voitures-hors-voirie
[nipkaart]: https://www.nipkaart.nl

<!-- MARKDOWN LINKS & IMAGES -->
Expand Down
27 changes: 22 additions & 5 deletions liege/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def from_dict(cls, data: dict[str, Any]) -> Garage:
url=attr.get("website"),
longitude=geo[0],
latitude=geo[1],
created_at=datetime.strptime(attr.get("created"), "%Y-%m-%d"),
updated_at=datetime.strptime(attr.get("last_modified"), "%Y-%m-%d"),
created_at=strptime(attr.get("created"), "%Y-%m-%d"),
updated_at=strptime(attr.get("last_modified"), "%Y-%m-%d"),
)


Expand All @@ -70,7 +70,7 @@ class DisabledParking:
longitude: float
latitude: float

created_at: datetime
created_at: datetime | None
updated_at: datetime

@classmethod
Expand All @@ -95,6 +95,23 @@ def from_dict(cls, data: dict[str, Any]) -> DisabledParking:
status=attr.get("status"),
longitude=geo[0],
latitude=geo[1],
created_at=datetime.strptime(attr.get("created"), "%Y-%m-%d"),
updated_at=datetime.strptime(attr.get("last_modified"), "%Y-%m-%d"),
created_at=strptime(attr.get("created"), "%Y-%m-%d"),
updated_at=strptime(attr.get("last_modified"), "%Y-%m-%d"),
)


def strptime(date_string: str, date_format: str, default: None = None) -> Any:
"""Strptime function with default value.
Args:
date_string: The date string.
date_format: The format of the date string.
default: The default value.
Returns:
The datetime object.
"""
try:
return datetime.strptime(date_string, date_format)
except (ValueError, TypeError):
return default
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Asynchronous Python client providing Open Data information of Gent."""
"""Asynchronous Python client providing Open Data information of Liege."""
import os


Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/disabled_parkings.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@
"gid": 1257,
"municipality": "Liège",
"street_name": "place des Abeilles",
"created": "2021-03-25",
"geo_shape": {
"coordinates": [
5.6330619893,
Expand Down

0 comments on commit 1a487ea

Please sign in to comment.