Skip to content

Commit 5528146

Browse files
committed
feat: LineID enum
1 parent a8ccf53 commit 5528146

File tree

4 files changed

+74
-12
lines changed

4 files changed

+74
-12
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ RatpAPI is a Python wrapper for interacting with the RATP (Régie Autonome des T
55

66
## Features
77
- Fetch global traffic information on the RATP network.
8-
- Retrieve traffic information for specific lines.
8+
- Retrieve traffic information for specific lines using the `LineID` enum for easy reference.
99
- Get affluence data for journeys on particular lines.
1010

1111
## Installation
12-
To use RatpAPI in your project, you can clone this repository:
12+
To use RatpAPI in your project, you can install it via pip:
1313
```bash
1414
pip install ratp-api-python
1515
```
@@ -22,7 +22,16 @@ First, import the `RatpAPI` class and initialize it with your API key:
2222
```python
2323
from ratp_api.main import RatpAPI
2424

25-
api = RatpAPI()
25+
api = RatpAPI(api_key="your_api_key")
26+
```
27+
28+
### Using the LineID Enum
29+
The `LineID` enum provides a convenient way to reference specific lines by their IDs:
30+
```python
31+
from ratp_api.enums import LineID
32+
33+
# Example: Using LineID for RER A
34+
line_id = LineID.RER_A
2635
```
2736

2837
### Fetching Global Traffic Information
@@ -33,9 +42,9 @@ print(global_traffic)
3342
```
3443

3544
### Fetching Line-Specific Traffic
36-
To get traffic information for a specific line:
45+
To get traffic information for a specific line using the `LineID` enum:
3746
```python
38-
line_traffic = api.get_line_traffic("line_id_here")
47+
line_traffic = api.get_line_traffic(LineID.RER_A)
3948
print(line_traffic)
4049
```
4150

@@ -44,7 +53,7 @@ To get affluence data for a specific journey on a line:
4453
```python
4554
start_coords = (longitude, latitude) # Start location coordinates
4655
end_coords = (longitude, latitude) # End location coordinates
47-
line_id = "line_id_here"
56+
line_id = LineID.RER_A # Using LineID enum
4857

4958
affluence_data = api.get_affluence(start=start_coords, end=end_coords, line_id=line_id)
5059
print(affluence_data)
@@ -61,6 +70,6 @@ print(all_lines_affluence)
6170
Contributions to the RatpAPI project are welcomed!
6271

6372
## License
64-
This project is licensed under MIT
73+
This project is licensed under the MIT License.
6574

66-
---
75+
---

src/ratp_api/affluence/__init__.py

Whitespace-only changes.
File renamed without changes.

src/ratp_api/main.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,64 @@
11
import json
22
import logging
33
import uuid
4+
from enum import Enum
45

56
import requests
67
from affluence.line_mappings import line_end_points
78

9+
logging.basicConfig(level=logging.INFO)
10+
11+
12+
class LineID(Enum):
13+
RER_A = "LIG:IDFM:C01742"
14+
RER_B = "LIG:IDFM:C01743"
15+
RER_C = "LIG:IDFM:C01727"
16+
RER_D = "LIG:IDFM:C01728"
17+
RER_E = "LIG:IDFM:C01729"
18+
TRANSILIEN_H = "LIG:IDFM:C01737"
19+
TRANSILIEN_J = "LIG:IDFM:C01739"
20+
TRANSILIEN_K = "LIG:IDFM:C01738"
21+
TRANSILIEN_L = "LIG:IDFM:C01740"
22+
TRANSILIEN_N = "LIG:IDFM:C01736"
23+
TRANSILIEN_P = "LIG:IDFM:C01730"
24+
TRANSILIEN_R = "LIG:IDFM:C01731"
25+
TRANSILIEN_U = "LIG:IDFM:C01741"
26+
METRO_1 = "LIG:IDFM:C01371"
27+
METRO_2 = "LIG:IDFM:C01372"
28+
METRO_3 = "LIG:IDFM:C01373"
29+
METRO_3BIS = "LIG:IDFM:C01386"
30+
METRO_4 = "LIG:IDFM:C01374"
31+
METRO_5 = "LIG:IDFM:C01375"
32+
METRO_6 = "LIG:IDFM:C01376"
33+
METRO_7 = "LIG:IDFM:C01377"
34+
METRO_7BIS = "LIG:IDFM:C01387"
35+
METRO_8 = "LIG:IDFM:C01378"
36+
METRO_9 = "LIG:IDFM:C01379"
37+
METRO_10 = "LIG:IDFM:C01380"
38+
METRO_11 = "LIG:IDFM:C01381"
39+
METRO_12 = "LIG:IDFM:C01382"
40+
METRO_13 = "LIG:IDFM:C01383"
41+
METRO_14 = "LIG:IDFM:C01384"
42+
METRO_FUNICULAIRE = "LIG:IDFM:C01385"
43+
METRO_ORLYVAL = "LIG:IDFM:C01388"
44+
TRAM_T1 = "LIG:IDFM:C01389"
45+
TRAM_T2 = "LIG:IDFM:C01390"
46+
TRAM_T3A = "LIG:IDFM:C01391"
47+
TRAM_T3B = "LIG:IDFM:C01679"
48+
TRAM_T4 = "LIG:IDFM:C01843"
49+
TRAM_T5 = "LIG:IDFM:C01684"
50+
TRAM_T6 = "LIG:IDFM:C01794"
51+
TRAM_T7 = "LIG:IDFM:C01774"
52+
TRAM_T8 = "LIG:IDFM:C01795"
53+
TRAM_T9 = "LIG:IDFM:C02317"
54+
TRAM_T10 = "LIG:IDFM:C02528"
55+
TRAM_T11_EXPRESS = "LIG:IDFM:C01999"
56+
TRAM_T12 = "LIG:IDFM:C02529"
57+
TRAM_T13 = "LIG:IDFM:C02344"
58+
59+
def __str__(self):
60+
return self.value
61+
862

963
class RatpAPI:
1064
"""
@@ -37,10 +91,9 @@ def get_session(self) -> requests.Session:
3791
"x-client-guid": self.x_client_guid,
3892
"x-client-platform": "bonjour_ios",
3993
"x-client-version": "latest",
40-
"Accept": "application/vnd.rss.bff.itinerary.v8+json",
41-
"Content-Type": "application/vnd.rss.bff.itineraries-query.v8+json",
4294
"User-Agent": "RATP/10.35.1 (com.ratp.ratp; build:231; iOS 17.0.3)",
4395
}
96+
4497
session.headers.update(headers)
4598
return session
4699

@@ -69,7 +122,7 @@ def get_global_traffic(self) -> dict:
69122
"""
70123
return self.make_request("GET", self.GLOBAL_TRAFFIC_URL)
71124

72-
def get_line_traffic(self, line_id: str) -> dict:
125+
def get_line_traffic(self, line_id: LineID) -> dict:
73126
"""
74127
Retrieve traffic information for a specific line.
75128
@@ -160,4 +213,4 @@ def get_all_lines_affluence(self):
160213

161214
if __name__ == "__main__":
162215
api = RatpAPI(api_key="e2rDkJzd2c1dPaFh7e0pJ9H7NjeqTQHg6ql31LmZ")
163-
logging.info(api.get_all_lines_affluence())
216+
print(api.get_line_traffic(line_id=LineID.METRO_1))

0 commit comments

Comments
 (0)