-
Notifications
You must be signed in to change notification settings - Fork 0
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
Benyamin Ginzburg
committed
Jun 26, 2021
1 parent
c1ea700
commit 86bc61f
Showing
16 changed files
with
217 additions
and
177 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
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,2 @@ | ||
class GtfsFileNotFound(Exception): | ||
pass |
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
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,13 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class Route: | ||
id: int | ||
agency_id: int | ||
short_name: str | ||
long_name: str | ||
description: str | ||
type: str | ||
color: str | ||
|
||
|
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 @@ | ||
init_query = ''' | ||
CREATE TABLE IF NOT EXISTS stops | ||
( | ||
id INT PRIMARY KEY, | ||
code INT UNIQUE, | ||
name TEXT NOT NULL, | ||
street TEXT NULL, | ||
city TEXT NOT NULL, | ||
platform TEXT NULL, | ||
floor TEXT NULL, | ||
location POINT NOT NULL, | ||
zone_id TEXT NULL | ||
); | ||
''' |
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 @@ | ||
from typing import Tuple, List, Optional | ||
|
||
|
||
def parse_stop_description(s: str) -> List[Optional[str]]: | ||
parts = s.split(':') | ||
values = [] | ||
for value in parts[1:-1]: | ||
value = value.rsplit(' ', maxsplit=1)[0].strip() | ||
if value: | ||
values.append(value) | ||
else: | ||
values.append(None) | ||
values.append(parts[-1].strip() or None) | ||
|
||
return values | ||
|
||
|
||
def parse_route_long_description(s: str) -> Tuple[str, str, str, str]: | ||
from_, to = s.split('<->') | ||
*from_stop_name, from_city = from_.split('-') | ||
from_stop_name = ' - '.join(from_stop_name) | ||
|
||
to_stop_name, to_city = to.split('-')[:2] | ||
|
||
return from_stop_name, from_city, to_stop_name, to_city |
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
File renamed without changes.
File renamed without changes.
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,51 @@ | ||
import logging | ||
from typing import List | ||
|
||
from httpx import AsyncClient | ||
from pydantic import parse_obj_as | ||
|
||
from israel_transport_api.config import SIRI_URL, API_KEY | ||
from israel_transport_api.siri.models import MonitoredStopVisit | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
class SiriClient: | ||
http_client: AsyncClient | ||
|
||
def __init__(self): | ||
self.http_client = AsyncClient() | ||
|
||
async def _make_request(self, station_id: int) -> List[MonitoredStopVisit]: | ||
params = { | ||
'Key': API_KEY, | ||
'MonitoringRef': station_id | ||
} | ||
|
||
resp = await self.http_client.get(SIRI_URL, params=params) | ||
raw_data: dict = resp.json() | ||
raw_stop_data: List[dict] = raw_data.get('Siri', {}).get('ServiceDelivery', {}).get('StopMonitoringDelivery', []) | ||
|
||
if len(raw_stop_data) == 0: | ||
print('no data') | ||
raise ValueError() | ||
|
||
if raw_stop_data[0]['Status'] != 'true': | ||
print('error', raw_stop_data) | ||
raise ValueError() | ||
|
||
parsed_data = parse_obj_as(List[MonitoredStopVisit], raw_stop_data[0]['MonitoredStopVisit']) | ||
return parsed_data | ||
|
||
|
||
|
||
|
||
import asyncio | ||
|
||
|
||
async def m(): | ||
c = SiriClient() | ||
resp = await c._make_request('32372') | ||
print(resp) | ||
|
||
asyncio.run(m()) |
Oops, something went wrong.