ltasg 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ltasg/__init__.py +5 -0
- ltasg/api.py +29 -0
- ltasg/constants.py +36 -0
- ltasg/traffic.py +2 -0
- ltasg/transport/__init__.py +0 -0
- ltasg/transport/bus.py +30 -0
- ltasg/transport/taxi.py +16 -0
- ltasg/transport/train.py +19 -0
- ltasg/transport/transport.py +9 -0
- ltasg-0.0.1.dist-info/METADATA +15 -0
- ltasg-0.0.1.dist-info/RECORD +13 -0
- ltasg-0.0.1.dist-info/WHEEL +4 -0
- ltasg-0.0.1.dist-info/licenses/LICENSE +21 -0
ltasg/__init__.py
ADDED
ltasg/api.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from aiohttp import ClientSession, ClientConnectionError
|
|
2
|
+
import traceback
|
|
3
|
+
class LTADataMall:
|
|
4
|
+
def __init__(self, api_key) -> None:
|
|
5
|
+
self.BASE_URL = "http://datamall2.mytransport.sg/ltaodataservice/"
|
|
6
|
+
self.API_KEY = api_key
|
|
7
|
+
self.HEADERS = {
|
|
8
|
+
"Accept": "application/json",
|
|
9
|
+
"AccountKey": self.API_KEY
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async def fetch(self, service_endpoint: str, query_params: dict=None, data:dict=None):
|
|
13
|
+
url = f"{self.BASE_URL}{service_endpoint}"
|
|
14
|
+
if query_params:
|
|
15
|
+
url += "?"
|
|
16
|
+
for param, value in query_params.items():
|
|
17
|
+
url += f"{param}={value}"
|
|
18
|
+
if param != list(query_params.keys())[-1]:
|
|
19
|
+
url += "&"
|
|
20
|
+
async with ClientSession() as session:
|
|
21
|
+
try:
|
|
22
|
+
async with session.get(url, headers=self.HEADERS) as response:
|
|
23
|
+
if response.status == 200:
|
|
24
|
+
return await response.json()
|
|
25
|
+
else:
|
|
26
|
+
raise Exception("Error calling api for {} with status code: {}".format(
|
|
27
|
+
service_endpoint, response.status)) from None
|
|
28
|
+
except ClientConnectionError as e:
|
|
29
|
+
raise e
|
ltasg/constants.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TransportType(Enum):
|
|
5
|
+
BUS = "bus"
|
|
6
|
+
TRAIN = "mrt"
|
|
7
|
+
TAXI = "taxi"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
LTA_SERVICES = {
|
|
11
|
+
"PUBLIC_TRANSPORT_SERVICES": {
|
|
12
|
+
TransportType.BUS: {
|
|
13
|
+
"ARRIVAL": "BusArrivalv2",
|
|
14
|
+
"SERVICES": "BusServices",
|
|
15
|
+
"ROUTES": "BusRoutes",
|
|
16
|
+
"STOPS": "BusStops",
|
|
17
|
+
# "PASSENGER_VOLUME": {
|
|
18
|
+
# "BUS_STOPS": "PV/Bus",
|
|
19
|
+
# "ORIGIN_TO_DEST": "PV/ODBus"
|
|
20
|
+
# }
|
|
21
|
+
},
|
|
22
|
+
TransportType.TRAIN: {
|
|
23
|
+
# "PASSENGER_VOLUME": {
|
|
24
|
+
# "ORIGIN_TO_DEST": "PV/ODTrain",
|
|
25
|
+
# },
|
|
26
|
+
"PLATFORM_CROWD_DENSITY": {
|
|
27
|
+
"REALTIME": "PCDRealTime",
|
|
28
|
+
"FORECAST": "PCDForecast"
|
|
29
|
+
},
|
|
30
|
+
"SERVICE_ALERTS": "TrainServiceAlerts"
|
|
31
|
+
},
|
|
32
|
+
TransportType.TAXI: {
|
|
33
|
+
"AVAILABILITY": "Taxi-Availability",
|
|
34
|
+
"STANDS": "TaxiStands",
|
|
35
|
+
}
|
|
36
|
+
}}
|
ltasg/traffic.py
ADDED
|
File without changes
|
ltasg/transport/bus.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from api import LTADataMall
|
|
2
|
+
from transport.transport import Transport
|
|
3
|
+
from constants import TransportType
|
|
4
|
+
|
|
5
|
+
class Bus(Transport):
|
|
6
|
+
def __init__(self, api_key):
|
|
7
|
+
super().__init__(api_key)
|
|
8
|
+
self.bus_services = self.transport_services[TransportType.BUS]
|
|
9
|
+
|
|
10
|
+
async def arrival(self, bus_stop_code: int, bus_no: int):
|
|
11
|
+
data = await self.lta_api.fetch(self.bus_services['ARRIVAL'], query_params={
|
|
12
|
+
"BusStopCode": bus_stop_code,
|
|
13
|
+
"ServiceNo": bus_no
|
|
14
|
+
})
|
|
15
|
+
return data["Services"]
|
|
16
|
+
|
|
17
|
+
async def services(self):
|
|
18
|
+
data = await self.lta_api.fetch(self.bus_services['SERVICES'])
|
|
19
|
+
return data["value"]
|
|
20
|
+
|
|
21
|
+
async def routes(self):
|
|
22
|
+
data = await self.lta_api.fetch(self.bus_services['ROUTES'])
|
|
23
|
+
return data["value"]
|
|
24
|
+
|
|
25
|
+
async def stops(self):
|
|
26
|
+
data = await self.lta_api.fetch(self.bus_services['STOPS'])
|
|
27
|
+
return data["value"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# BusArrivalv2?BusStopCode=71111&ServiceNo=137
|
ltasg/transport/taxi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from transport.transport import Transport
|
|
2
|
+
from constants import TransportType
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Taxi(Transport):
|
|
6
|
+
def __init__(self, api_key) -> None:
|
|
7
|
+
super().__init__(api_key)
|
|
8
|
+
self.taxi_services = self.transport_services[TransportType.TAXI]
|
|
9
|
+
|
|
10
|
+
async def availability(self):
|
|
11
|
+
data = await self.lta_api.fetch(self.taxi_services["AVAILABILITY"])
|
|
12
|
+
return data['value']
|
|
13
|
+
|
|
14
|
+
async def stands(self):
|
|
15
|
+
data = await self.lta_api.fetch(self.taxi_services["STANDS"])
|
|
16
|
+
return data['value']
|
ltasg/transport/train.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from transport.transport import Transport
|
|
2
|
+
from constants import TransportType
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
class Train(Transport):
|
|
6
|
+
def __init__(self, api_key) -> None:
|
|
7
|
+
super().__init__(api_key)
|
|
8
|
+
self.train_services = self.transport_services[TransportType.TRAIN]
|
|
9
|
+
|
|
10
|
+
async def service_alerts(self):
|
|
11
|
+
data = await self.lta_api.fetch(self.train_services['SERVICE_ALERTS'])
|
|
12
|
+
return data['value']
|
|
13
|
+
|
|
14
|
+
# API currently results in Error 404 not found
|
|
15
|
+
# async def platform_crowd_density(self, type: Literal["realtime", "forecast"] = "realtime"):
|
|
16
|
+
# if type == "realtime":
|
|
17
|
+
# return await self.lta_api.fetch(self.train_services["PLATFORM_CROWD_DENSITY"]['REALTIME'])
|
|
18
|
+
# else:
|
|
19
|
+
# return await self.lta_api.fetch(self.train_services["PLATFORM_CROWD_DENSITY"]["FORECAST"])
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: ltasg
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A LTA Datamall API Wrapper Library for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/ashe/ltasg
|
|
6
|
+
Project-URL: Issues, https://github.com/ashe/ltasg/issues
|
|
7
|
+
Author-email: Aw Sheng Xiang <awshengxiang@hotmail.com>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# ltasg
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ltasg/__init__.py,sha256=Ad1sqqFDheWrAP47UrPJaV8wg8XPVbJqmXxSDfIyGP0,115
|
|
2
|
+
ltasg/api.py,sha256=82nQORX48ac4jNxhcwXB59dghLRiqCdl1QDQUnEBQTg,1272
|
|
3
|
+
ltasg/constants.py,sha256=-VPdc29e1yrdf8WfSv6SxJDAp5Dvo2Hl-B9-3Q817ms,983
|
|
4
|
+
ltasg/traffic.py,sha256=THy6DQbo97N_gr2x1F9mIHXNmHTJbpApIJNPs9mk-2s,31
|
|
5
|
+
ltasg/transport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
ltasg/transport/bus.py,sha256=KN1DQtd6aHniU-HI-T2WF3wvpt08JAkcooYQcfSlYMg,1000
|
|
7
|
+
ltasg/transport/taxi.py,sha256=T_36NAqCDX4bMUYV_u-ublrat1GB7w6Dwpz3IweQfJE,537
|
|
8
|
+
ltasg/transport/train.py,sha256=H1m3uqteT0GQh9U-M4Mth2kemeiq40ilMDpYmC5ZkIc,855
|
|
9
|
+
ltasg/transport/transport.py,sha256=MVp9aZFnYQupbbQZRPgpqkzpJv9pUqEsPc6PKR8H_D0,263
|
|
10
|
+
ltasg-0.0.1.dist-info/METADATA,sha256=aV61APtMcZEpkIJedAQjx6w_tdXGqWcadMtz4Z-7JhU,510
|
|
11
|
+
ltasg-0.0.1.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
|
12
|
+
ltasg-0.0.1.dist-info/licenses/LICENSE,sha256=Ek8jf_lINFv3z5tUpSKltxgG4kO149536yWu352HCZU,1082
|
|
13
|
+
ltasg-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ashe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|