m-car-api 1.0.0__tar.gz

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.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.1
2
+ Name: m_car_api
3
+ Version: 1.0.0
4
+ Home-page: https://github.com/cbrand/mapi
5
+ Author: Christoph Brand
6
+ Author-email: christoph@brand.rest
7
+ License: MIT
8
+ Project-URL: GitHub, https://github.com/cbrand/m_car_api
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: requests
21
+ Requires-Dist: pydantic>=2
22
+ Requires-Dist: mujson
23
+ Requires-Dist: pyproj
24
+ Provides-Extra: test
25
+ Requires-Dist: black>=19.10b0; extra == "test"
26
+ Requires-Dist: coverage<7,>=5.1; extra == "test"
27
+ Requires-Dist: faker<19,>=18; extra == "test"
28
+ Requires-Dist: flake8<6,>=5.0.4; extra == "test"
29
+ Requires-Dist: mypy>=0.961; extra == "test"
30
+ Requires-Dist: pre-commit<4,>=3; extra == "test"
31
+ Requires-Dist: pytest-cases<4,>=3.1.1; extra == "test"
32
+ Requires-Dist: pytest-html; extra == "test"
33
+ Requires-Dist: pytest<8,>=7; extra == "test"
34
+ Requires-Dist: pytest-mock<4,>=3.5.1; extra == "test"
35
+ Requires-Dist: python-dotenv<2,>=1; extra == "test"
36
+ Requires-Dist: python-semantic-release<9,>=8; extra == "test"
37
+ Requires-Dist: twine<4,>=3.1.1; extra == "test"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,78 @@
1
+ import os
2
+ import sys
3
+ from typing import Dict, List
4
+
5
+ from setuptools import find_namespace_packages, setup
6
+
7
+ sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
8
+
9
+ CURRENT_PYTHON = sys.version_info[:2]
10
+ REQUIRED_PYTHON = (3, 10)
11
+ EGG_NAME = "m_car_api"
12
+
13
+
14
+ def list_packages(source_directory: str = "src") -> List[str]:
15
+ packages = list(find_namespace_packages(source_directory, exclude="venv"))
16
+ return packages
17
+
18
+
19
+ def list_namespace_packages(source_directory: str = "src") -> List[str]:
20
+ return []
21
+
22
+
23
+ def get_package_dir() -> Dict[str, str]:
24
+ if not os.path.isdir("src"):
25
+ return {}
26
+ return {"": "src"}
27
+
28
+
29
+ __version__ = "1.0.0"
30
+ requirements = ["requests", "pydantic>=2", "mujson", "pyproj"]
31
+ test_requirements = [
32
+ "black>=19.10b0",
33
+ "coverage>=5.1,<7",
34
+ "faker>=18,<19",
35
+ "flake8>=5.0.4,<6",
36
+ "mypy>=0.961",
37
+ "pre-commit>=3,<4",
38
+ "pytest-cases>=3.1.1,<4",
39
+ "pytest-html",
40
+ "pytest>=7,<8",
41
+ "pytest-mock>=3.5.1,<4",
42
+ "python-dotenv>=1,<2",
43
+ "python-semantic-release>=8,<9",
44
+ "twine>=3.1.1,<4",
45
+ ]
46
+
47
+
48
+ setup(
49
+ name=EGG_NAME,
50
+ version=__version__,
51
+ python_requires=">={}.{}".format(*REQUIRED_PYTHON),
52
+ url="https://github.com/cbrand/mapi",
53
+ author="Christoph Brand",
54
+ author_email="christoph@brand.rest",
55
+ description="",
56
+ long_description="",
57
+ license="MIT",
58
+ packages=list_packages(),
59
+ package_dir=get_package_dir(),
60
+ include_package_data=True,
61
+ install_requires=requirements,
62
+ zip_safe=False,
63
+ classifiers=[
64
+ "Development Status :: 5 - Production/Stable",
65
+ "Intended Audience :: Developers",
66
+ "Operating System :: OS Independent",
67
+ "Programming Language :: Python",
68
+ "Programming Language :: Python :: 3",
69
+ "Programming Language :: Python :: 3.10",
70
+ "Programming Language :: Python :: 3.11",
71
+ "Programming Language :: Python :: 3.12",
72
+ "Programming Language :: Python :: 3 :: Only",
73
+ "Topic :: Software Development :: Libraries :: Python Modules",
74
+ ],
75
+ extras_require={"test": test_requirements},
76
+ project_urls={"GitHub": "https://github.com/cbrand/m_car_api"},
77
+ namespace_packages=list_namespace_packages(),
78
+ )
@@ -0,0 +1,4 @@
1
+ # flake8: noqa: F401
2
+
3
+ from .api import MApi, vehicles, vehicles_meters_around_location
4
+ from .objects import Vehicle
@@ -0,0 +1,190 @@
1
+ from __future__ import annotations
2
+ from typing import Any
3
+ import requests
4
+ from base64 import b64decode
5
+ from urllib.parse import urljoin
6
+ from pyproj import Geod
7
+
8
+ from m_car_api.const import U_HEL_URL_PATH, V_URL_PATH, DEFAULT_ROOT_URL
9
+ from m_car_api.objects import (
10
+ DeviceInfo,
11
+ Vehicle,
12
+ VehicleQuery,
13
+ VehicleReturn,
14
+ APIReturn,
15
+ )
16
+
17
+ geod = Geod(ellps="WGS84")
18
+
19
+
20
+ class SubAPI:
21
+ def __init__(self, mapi: MApi) -> None:
22
+ self.mapi = mapi
23
+
24
+ @property
25
+ def device_key(self) -> str:
26
+ return self.mapi.device_key
27
+
28
+ @property
29
+ def root_url(self) -> str:
30
+ return self.mapi.root_url
31
+
32
+ def _hello_if_not_done(self) -> bool:
33
+ return self.mapi.hello_if_not_done()
34
+
35
+
36
+ class VehiclesSearchAPI(SubAPI):
37
+ def __init__(
38
+ self,
39
+ mapi: MApi,
40
+ lat: float,
41
+ lon: float,
42
+ latitude_delta: float,
43
+ longitude_delta: float,
44
+ query: VehicleQuery | None = None,
45
+ ) -> None:
46
+ super().__init__(mapi)
47
+ self.lat = lat
48
+ self.lon = lon
49
+ self.latitude_delta = latitude_delta
50
+ self.longitude_delta = longitude_delta
51
+ self.query = query or VehicleQuery()
52
+
53
+ def raw_json_response(self, path: str = V_URL_PATH) -> str:
54
+ self._hello_if_not_done()
55
+ vehicles_url = urljoin(self.root_url, path)
56
+ params = self.query.to_params(
57
+ latitude=self.lat,
58
+ longitude=self.lon,
59
+ latitude_delta=self.latitude_delta,
60
+ longitude_delta=self.longitude_delta,
61
+ )
62
+ params["deviceKey"] = self.device_key
63
+ response = requests.get(vehicles_url, params=params)
64
+ response.raise_for_status()
65
+ return response.text
66
+
67
+ def vehicles_return(self) -> VehicleReturn:
68
+ result = APIReturn[VehicleReturn].model_validate_json(self.raw_json_response())
69
+ if result.result != "OK":
70
+ raise ValueError(result.message)
71
+ return result.data
72
+
73
+
74
+ class MApi:
75
+ def __init__(self, device_key: str, root_url: str = DEFAULT_ROOT_URL) -> None:
76
+ self.device_key = device_key
77
+ self.root_url = root_url
78
+ self._hello_done = False
79
+
80
+ def hello(
81
+ self, device_info: DeviceInfo | None = None, path: str = U_HEL_URL_PATH
82
+ ) -> bool:
83
+ device_info = device_info or DeviceInfo()
84
+ url = urljoin(self.root_url, path)
85
+ params = {
86
+ "deviceKey": self.device_key,
87
+ **device_info.to_params(),
88
+ }
89
+ response = requests.get(url, params=params)
90
+ response.raise_for_status()
91
+
92
+ result = response.json()["Result"] == "ok"
93
+ if result:
94
+ self._hello_done = True
95
+ return result
96
+
97
+ def hello_if_not_done(self, device_info: DeviceInfo | None = None) -> bool:
98
+ if not self._hello_done:
99
+ return self.hello(device_info=device_info)
100
+ return True
101
+
102
+ def vehicles_return(
103
+ self,
104
+ lat: float,
105
+ lon: float,
106
+ latitude_delta: float,
107
+ longitude_delta: float,
108
+ query: VehicleQuery | None = None,
109
+ ) -> VehicleReturn:
110
+ return VehiclesSearchAPI(
111
+ mapi=self,
112
+ lat=lat,
113
+ lon=lon,
114
+ latitude_delta=latitude_delta,
115
+ longitude_delta=longitude_delta,
116
+ query=query,
117
+ ).vehicles_return()
118
+
119
+ def vehicles(
120
+ self,
121
+ lat: float,
122
+ lon: float,
123
+ latitude_delta: float,
124
+ longitude_delta: float,
125
+ query: VehicleQuery | None = None,
126
+ ) -> dict[str, Any]:
127
+ return self.vehicles_return(
128
+ lat=lat,
129
+ lon=lon,
130
+ latitude_delta=latitude_delta,
131
+ longitude_delta=longitude_delta,
132
+ query=query,
133
+ ).vehicles
134
+
135
+ def vehicles_return_meters_around_location(
136
+ self, lat: float, lon: float, meters: float, query: VehicleQuery | None = None
137
+ ) -> VehicleReturn:
138
+ lon_top_left, lat_top_left, _ = geod.fwd(lon, lat, 315, meters)
139
+ lon_bottom_right, lat_bottom_right, _ = geod.fwd(lon, lat, 135, meters)
140
+ lat_delta = abs(lat_top_left - lat_bottom_right)
141
+ lon_delta = abs(lon_top_left - lon_bottom_right)
142
+ return self.vehicles_return(
143
+ lat=lat,
144
+ lon=lon,
145
+ latitude_delta=lat_delta,
146
+ longitude_delta=lon_delta,
147
+ query=query,
148
+ )
149
+
150
+ def vehicles_meters_around_location(
151
+ self, lat: float, lon: float, meters: float, query: VehicleQuery | None = None
152
+ ) -> dict[str, Any]:
153
+ return self.vehicles_return_meters_around_location(
154
+ lat=lat,
155
+ lon=lon,
156
+ meters=meters,
157
+ query=query,
158
+ ).vehicles
159
+
160
+
161
+ def vehicles(
162
+ device_key: str,
163
+ lat: float,
164
+ lon: float,
165
+ latitude_delta: float,
166
+ longitude_delta: float,
167
+ query: VehicleQuery | None = None,
168
+ ) -> list[Vehicle]:
169
+ return MApi(device_key=device_key).vehicles(
170
+ lat=lat,
171
+ lon=lon,
172
+ latitude_delta=latitude_delta,
173
+ longitude_delta=longitude_delta,
174
+ query=query,
175
+ )
176
+
177
+
178
+ def vehicles_meters_around_location(
179
+ device_key: str,
180
+ lat: float,
181
+ lon: float,
182
+ meters: float,
183
+ query: VehicleQuery | None = None,
184
+ ) -> list[Vehicle]:
185
+ return MApi(device_key=device_key).vehicles_meters_around_location(
186
+ lat=lat,
187
+ lon=lon,
188
+ meters=meters,
189
+ query=query,
190
+ )
@@ -0,0 +1,84 @@
1
+ OBSUFACTOR_TOKEN = 234
2
+ DEFAULT_ROOT_URL = bytes(
3
+ i ^ OBSUFACTOR_TOKEN
4
+ for i in (
5
+ 130,
6
+ 158,
7
+ 158,
8
+ 154,
9
+ 153,
10
+ 208,
11
+ 197,
12
+ 197,
13
+ 139,
14
+ 154,
15
+ 131,
16
+ 196,
17
+ 139,
18
+ 154,
19
+ 154,
20
+ 196,
21
+ 135,
22
+ 131,
23
+ 134,
24
+ 143,
25
+ 153,
26
+ 199,
27
+ 135,
28
+ 133,
29
+ 136,
30
+ 131,
31
+ 134,
32
+ 131,
33
+ 158,
34
+ 147,
35
+ 196,
36
+ 137,
37
+ 133,
38
+ 135,
39
+ 197,
40
+ )
41
+ ).decode("utf-8")
42
+ V_URL_PATH = bytes(
43
+ i ^ OBSUFACTOR_TOKEN
44
+ for i in (
45
+ 197,
46
+ 135,
47
+ 133,
48
+ 136,
49
+ 131,
50
+ 134,
51
+ 143,
52
+ 197,
53
+ 188,
54
+ 143,
55
+ 130,
56
+ 131,
57
+ 137,
58
+ 134,
59
+ 143,
60
+ 153,
61
+ )
62
+ ).decode("utf-8")
63
+ U_HEL_URL_PATH = bytes(
64
+ i ^ OBSUFACTOR_TOKEN
65
+ for i in (
66
+ 197,
67
+ 135,
68
+ 133,
69
+ 136,
70
+ 131,
71
+ 134,
72
+ 143,
73
+ 197,
74
+ 191,
75
+ 153,
76
+ 143,
77
+ 152,
78
+ 162,
79
+ 143,
80
+ 134,
81
+ 134,
82
+ 133,
83
+ )
84
+ ).decode("utf-8")
@@ -0,0 +1,266 @@
1
+ import mujson
2
+ from datetime import datetime
3
+ from typing import Any, Generic, Literal, NamedTuple, TypeVar
4
+ from pydantic import BaseModel, Field, computed_field
5
+
6
+
7
+ class DeviceInfo(NamedTuple):
8
+ owner_name: str = "unknown"
9
+ device_info1: str = "Linux"
10
+ device_info2: str = "amd64"
11
+ os_info1: str = "Linux"
12
+ os_info2: str = "6.8.2-generic"
13
+ app_version: str = "4.31+(210440)"
14
+ lang: str = "en"
15
+ translation_dictionary_timestamp: datetime = datetime(year=2001, month=1, day=1)
16
+ city_areas_timestamp: datetime = datetime(2020, 1, 3)
17
+
18
+ def to_params(self) -> dict[str, Any]:
19
+ return {
20
+ "ownerName": self.owner_name,
21
+ "deviceInfo1": self.device_info1,
22
+ "deviceInfo2": self.device_info2,
23
+ "osInfo1": self.os_info1,
24
+ "osInfo2": self.os_info2,
25
+ "appVersion": self.app_version,
26
+ "lang": self.lang,
27
+ "translationDictionaryTimestamp": self.translation_dictionary_timestamp.isoformat(
28
+ sep=" "
29
+ ),
30
+ "cityAreasTimestamp": self.city_areas_timestamp.isoformat(sep=" "),
31
+ }
32
+
33
+
34
+ class VehicleQuery(NamedTuple):
35
+ user_latitude: float | None = None
36
+ user_longitude: float | None = None
37
+ fuel_level_filter_min: int = 0
38
+ fuel_level_filter_max: int = 100
39
+ vehicle_size_filter: tuple[str, ...] | None = None
40
+ vehicle_engine_filter: str | None = None
41
+ vehicle_seats_filter: tuple[int, ...] | None = None
42
+ zoom_level: int = 10
43
+ show_only_discounted_vehicles: bool = False
44
+ show_fueling_stations: bool = False
45
+ show_charging_stations: bool = False
46
+ show_miles_partners: bool = False
47
+
48
+ def to_params(
49
+ self,
50
+ latitude: float,
51
+ longitude: float,
52
+ latitude_delta: float,
53
+ longitude_delta: float,
54
+ ) -> dict[str, Any]:
55
+ return {
56
+ "latitude": latitude,
57
+ "longitude": longitude,
58
+ "latitudeDelta": latitude_delta,
59
+ "longitudeDelta": longitude_delta,
60
+ "userLatitude": self.user_latitude or latitude,
61
+ "userLongitude": self.user_longitude or longitude,
62
+ "FuelLevelFilterMin": self.fuel_level_filter_min,
63
+ "FuelLevelFilterMax": self.fuel_level_filter_max,
64
+ "VehicleSizeFilter": (
65
+ ",".join(self.vehicle_size_filter) if self.vehicle_size_filter else None
66
+ ),
67
+ "vehicleEngineFilter": self.vehicle_engine_filter,
68
+ "VehicleSeatsFilter": (
69
+ ",".join(map(str, self.vehicle_seats_filter))
70
+ if self.vehicle_seats_filter
71
+ else None
72
+ ),
73
+ "zoomLevel": self.zoom_level,
74
+ "showOnlyDiscountedVehicles": int(self.show_only_discounted_vehicles),
75
+ "showFuelingStations": int(self.show_fueling_stations),
76
+ "showChargingStations": int(self.show_charging_stations),
77
+ "showMilesPartners": int(self.show_miles_partners),
78
+ }
79
+
80
+
81
+ class RentalPrice(BaseModel):
82
+ price: str
83
+ unit: str
84
+ discounted: bool = False
85
+ description: str = ""
86
+ discount_source: str | None = None
87
+
88
+
89
+ class ParkingPrice(BaseModel):
90
+ price: str
91
+ unit: str
92
+ discounted: bool = False
93
+
94
+
95
+ class UnlockFee(BaseModel):
96
+ price: str
97
+ unit: str
98
+ discounted: bool
99
+
100
+
101
+ class Destination(BaseModel):
102
+ destination: str = Field(alias="Destination")
103
+
104
+
105
+ class DestinationWithPrice(Destination):
106
+ city_id: str = Field(alias="idCity")
107
+ price: str = Field(alias="Price")
108
+ price_discounted: str | None = Field(alias="Price_discounted")
109
+
110
+
111
+ class CityToCityOptions(BaseModel):
112
+ origin_city: str = Field(alias="OriginCity")
113
+ destinations_raw: list[DestinationWithPrice] | None = Field(
114
+ alias="Destinations", exclude=True
115
+ )
116
+
117
+ @property
118
+ @computed_field
119
+ def destinations(self) -> list[DestinationWithPrice]:
120
+ return self.destinations_raw or []
121
+
122
+ not_possible_destinations_raw: list[Destination] | None = Field(
123
+ alias="NotPossibleDestinations", exclude=True
124
+ )
125
+
126
+ @property
127
+ @computed_field
128
+ def not_possible_destinations(self) -> list[Destination]:
129
+ return self.not_possible_destinations_raw or []
130
+
131
+
132
+ class Vehicle(BaseModel):
133
+ id: int = Field(alias="idVehicle")
134
+ city_id: str = Field(alias="idCity")
135
+ license_plate: str = Field(alias="LicensePlate")
136
+ type: str = Field(alias="VehicleType")
137
+ color: str = Field(alias="VehicleColor")
138
+ size: Literal["S", "M", "L", "X", "P"] = Field(alias="VehicleSize")
139
+ electric: bool = Field(alias="isElectric")
140
+ latitude: float = Field(alias="Latitude")
141
+ longitude: float = Field(alias="Longitude")
142
+ distance_from_user_position: float = Field(alias="DistanceFromUserPosition")
143
+ distance_from_middle_position: float = Field(alias="DistanceFromMiddlePosition")
144
+ status: str = Field(alias="idVehicleStatus")
145
+ gsm_coverage: int = Field(alias="GSMCoverage")
146
+ satellite_number: int = Field(alias="SatelliteNumber")
147
+
148
+ rental_price_row_1: str = Field(alias="RentalPrice_row1", exclude=True)
149
+ rental_price_row_1_unit: str = Field(alias="RentalPrice_row1unit", exclude=True)
150
+ rental_price_discounted: str | None = Field(
151
+ alias="RentalPrice_discounted", exclude=True
152
+ )
153
+ rental_price_row_2: str = Field(alias="RentalPrice_row2", exclude=True)
154
+ rental_price_discount_source: str | None = Field(
155
+ alias="RentalPrice_discountSource", exclude=True
156
+ )
157
+
158
+ @computed_field
159
+ @property
160
+ def rental_price(self) -> RentalPrice:
161
+ return RentalPrice(
162
+ price=self.rental_price_row_1,
163
+ unit=self.rental_price_row_1_unit,
164
+ discounted=bool(self.rental_price_discounted),
165
+ description=self.rental_price_row_2,
166
+ discount_source=self.rental_price_discount_source,
167
+ )
168
+
169
+ parking_price_item: str = Field(alias="ParkingPrice", exclude=True)
170
+ parking_price_discounted: bool | str | None = Field(
171
+ alias="ParkingPrice_discounted", exclude=True
172
+ )
173
+ parking_price_unit: str = Field(alias="ParkingPrice_unit", exclude=True)
174
+
175
+ @computed_field
176
+ @property
177
+ def parking_price(self) -> ParkingPrice:
178
+ return ParkingPrice(
179
+ price=self.parking_price_item,
180
+ unit=self.parking_price_unit,
181
+ discounted=bool(self.parking_price_discounted),
182
+ )
183
+
184
+ unlock_fee_item: str = Field(alias="UnlockFee", exclude=True)
185
+ unlock_fee_discounted: str | None = Field(
186
+ alias="UnlockFee_discounted", exclude=True
187
+ )
188
+ unlock_fee_unit: str = Field(alias="UnlockFee_unit", exclude=True)
189
+
190
+ @computed_field
191
+ @property
192
+ def unlock_fee(self) -> UnlockFee:
193
+ return UnlockFee(
194
+ price=self.unlock_fee_item,
195
+ unit=self.unlock_fee_unit,
196
+ discounted=bool(self.unlock_fee_discounted),
197
+ )
198
+
199
+ fuel_percent: str = Field(alias="FuelPct")
200
+ fuel_level_icon: int = Field(alias="FuelLevelIcon")
201
+ remaining_range: str = Field(alias="RemainingRange")
202
+ ev_plugged: bool = Field(alias="EVPlugged")
203
+ fvd_price: str = Field(alias="FVDPrice")
204
+ url_vehicle_image: str = Field(alias="URLVehicleImage")
205
+ rookie_delay_txt: str = Field(alias="RookieDelayTxt")
206
+ number_days_rookies_delay: int = Field(alias="nDaysRookieDelay")
207
+ premium_restricted_txt: str = Field(alias="PremiumRestrictedTxt")
208
+ city_to_city_options_string: str | None = Field(
209
+ alias="CityToCityOptions", exclude=True
210
+ )
211
+
212
+ @computed_field
213
+ @property
214
+ def city_to_city_options(self) -> CityToCityOptions:
215
+ return CityToCityOptions.model_validate_json(self.city_to_city_options_string)
216
+
217
+ json_vehicle_damages_input: str | None = Field(
218
+ alias="JSONVehicleDamages", exclude=True
219
+ )
220
+
221
+ @computed_field
222
+ @property
223
+ def json_vehicle_damages(self) -> list[dict[str, Any]]:
224
+ if self.json_vehicle_damages_input is None:
225
+ return []
226
+ else:
227
+ return mujson.loads(self.json_vehicle_damages_input)
228
+
229
+ json_vehicle_banner: str | None = Field(alias="JSONVehicleBanner")
230
+
231
+
232
+ class VehicleResponse(BaseModel):
233
+ result: str = Field(alias="Result")
234
+ response_text: str | None = Field(alias="ResponseText")
235
+ id_vehicle_booked: str | None = Field(alias="idVehicleBooked")
236
+ id_ride: str | None = Field(alias="idRide")
237
+ id_vehicle_in_ride: str | None = Field(alias="idVehicleInRide")
238
+ nearest_id_city: str | None = Field(alias="NearestIdCity")
239
+ live_payment: bool = Field(alias="LivePayment")
240
+ top_up_required: bool = Field(alias="TopUpRequired")
241
+ user_app_version: str | float = Field(alias="userAppVersion")
242
+ n_filter_elements: int = Field(alias="nFilterElements")
243
+ user_in_ops_mode: bool = Field(alias="UserInOpsMode")
244
+ special_airport_rate: str | None = Field(alias="SpecialAirportRate")
245
+ special_airport_rate_e: str | None = Field(alias="SpecialAirportRate_E")
246
+ special_airport_rate_2: str | None = Field(alias="SpecialAirportRate_2")
247
+ special_airport_rate_e_2: str | None = Field(alias="SpecialAirportRate_E_2")
248
+ uses_ppc: bool = Field(alias="UsesPPC")
249
+ current_subscription: str | None = Field(alias="CurrentSubscription")
250
+ json_city_areas: str = Field(alias="JSONCityAreas")
251
+ city_areas_timestamp: datetime = Field(alias="CityAreasTimestamp")
252
+ additional_info: str = Field(alias="AdditionalInfo")
253
+
254
+
255
+ class VehicleReturn(BaseModel):
256
+ response: VehicleResponse = Field(alias="response")
257
+ vehicles: list[Vehicle] = Field(alias="vehicles")
258
+
259
+
260
+ APIData = TypeVar("APIData")
261
+
262
+
263
+ class APIReturn(BaseModel, Generic[APIData]):
264
+ result: str = Field(alias="Result")
265
+ response_text: str | None = Field(alias="ResponseText")
266
+ data: APIData = Field(alias="Data")
@@ -0,0 +1,33 @@
1
+ from uuid import UUID, uuid4
2
+ import pytest
3
+ from m_car_api import vehicles, vehicles_meters_around_location
4
+
5
+
6
+ @pytest.fixture
7
+ def device_key(request: pytest.FixtureRequest) -> str:
8
+ device_key = request.config.cache.get("mapi/device-key", None)
9
+ if device_key is None:
10
+ device_key = str(uuid4())
11
+ request.config.cache.set("mapi/device-key", device_key)
12
+ return device_key
13
+
14
+
15
+ def test_vehicles(device_key: str) -> None:
16
+ response = vehicles(
17
+ device_key=device_key,
18
+ lat=52.520008,
19
+ lon=13.404954,
20
+ latitude_delta=0.1,
21
+ longitude_delta=0.1,
22
+ )
23
+ assert isinstance(response, list)
24
+
25
+
26
+ def test_vehicles_meters_around_location(device_key: str) -> None:
27
+ response = vehicles_meters_around_location(
28
+ device_key=device_key,
29
+ lat=52.520008,
30
+ lon=13.404954,
31
+ meters=500,
32
+ )
33
+ assert isinstance(response, list)
@@ -0,0 +1,23 @@
1
+ import pytest
2
+
3
+ from pathlib import Path
4
+ from m_car_api.objects import APIReturn, VehicleReturn
5
+
6
+
7
+ @pytest.fixture(scope="session")
8
+ def vehicle_json_path() -> Path:
9
+ return Path(__file__).parent / "vehicle_return.json"
10
+
11
+
12
+ @pytest.fixture(scope="session")
13
+ def vehicle_json(vehicle_json_path: str) -> str:
14
+ with open(vehicle_json_path) as f:
15
+ return f.read()
16
+
17
+
18
+ def test_vehicle_check(vehicle_json: str):
19
+ result = APIReturn[VehicleReturn].model_validate_json(vehicle_json)
20
+ assert isinstance(result, APIReturn[VehicleReturn])
21
+ first_vehicle = result.data.vehicles[0]
22
+ first_vehicle.id == 10326
23
+ first_vehicle.license_plate == "B-MS 4309"
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.1
2
+ Name: m_car_api
3
+ Version: 1.0.0
4
+ Home-page: https://github.com/cbrand/mapi
5
+ Author: Christoph Brand
6
+ Author-email: christoph@brand.rest
7
+ License: MIT
8
+ Project-URL: GitHub, https://github.com/cbrand/m_car_api
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: requests
21
+ Requires-Dist: pydantic>=2
22
+ Requires-Dist: mujson
23
+ Requires-Dist: pyproj
24
+ Provides-Extra: test
25
+ Requires-Dist: black>=19.10b0; extra == "test"
26
+ Requires-Dist: coverage<7,>=5.1; extra == "test"
27
+ Requires-Dist: faker<19,>=18; extra == "test"
28
+ Requires-Dist: flake8<6,>=5.0.4; extra == "test"
29
+ Requires-Dist: mypy>=0.961; extra == "test"
30
+ Requires-Dist: pre-commit<4,>=3; extra == "test"
31
+ Requires-Dist: pytest-cases<4,>=3.1.1; extra == "test"
32
+ Requires-Dist: pytest-html; extra == "test"
33
+ Requires-Dist: pytest<8,>=7; extra == "test"
34
+ Requires-Dist: pytest-mock<4,>=3.5.1; extra == "test"
35
+ Requires-Dist: python-dotenv<2,>=1; extra == "test"
36
+ Requires-Dist: python-semantic-release<9,>=8; extra == "test"
37
+ Requires-Dist: twine<4,>=3.1.1; extra == "test"
@@ -0,0 +1,14 @@
1
+ setup.py
2
+ src/m_car_api/__init__.py
3
+ src/m_car_api/api.py
4
+ src/m_car_api/const.py
5
+ src/m_car_api/objects.py
6
+ src/m_car_api.egg-info/PKG-INFO
7
+ src/m_car_api.egg-info/SOURCES.txt
8
+ src/m_car_api.egg-info/dependency_links.txt
9
+ src/m_car_api.egg-info/namespace_packages.txt
10
+ src/m_car_api.egg-info/not-zip-safe
11
+ src/m_car_api.egg-info/requires.txt
12
+ src/m_car_api.egg-info/top_level.txt
13
+ src/m_car_api/test/test_miles_api.py
14
+ src/m_car_api/test/test_objects.py
@@ -0,0 +1,19 @@
1
+ requests
2
+ pydantic>=2
3
+ mujson
4
+ pyproj
5
+
6
+ [test]
7
+ black>=19.10b0
8
+ coverage<7,>=5.1
9
+ faker<19,>=18
10
+ flake8<6,>=5.0.4
11
+ mypy>=0.961
12
+ pre-commit<4,>=3
13
+ pytest-cases<4,>=3.1.1
14
+ pytest-html
15
+ pytest<8,>=7
16
+ pytest-mock<4,>=3.5.1
17
+ python-dotenv<2,>=1
18
+ python-semantic-release<9,>=8
19
+ twine<4,>=3.1.1
@@ -0,0 +1 @@
1
+ m_car_api