-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
50 lines (44 loc) · 1.43 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from pydantic import BaseModel
import datetime
from datetime import datetime
from enum import Enum
class IncidentType(Enum):
INJURIES = 0
TRAVELER_INFO = 1,
TEST_API = 2,
CRASHES = 3
class Properties(BaseModel):
injuries: int
route_name: str
last_updated: datetime
traveler_information_message: str
class Geometry(BaseModel):
srid: int
type: str
class Feature(BaseModel):
type: str
geometry: Geometry
properties: Properties
class FeatureCollection:
def __init__(self):
self.features: [] = []
def parse_from_json(self, json_dict: dict):
for f in json_dict['features']:
try:
self.features.append(
Feature(
type=f['type'],
geometry=Geometry(
srid=f['geometry']['srid'],
type=f['geometry']['type'],
),
properties=Properties(
injuries=f['properties']['injuries'],
route_name=f['properties']['routeName'],
last_updated=datetime.strptime(f['properties']['lastUpdated'], '%Y-%m-%dT%H:%M:%S.%fZ'),
traveler_information_message=f['properties']['travelerInformationMessage']
)
)
)
except:
print("Failed to parse a feature{}".format(f))