python-terminusgps 1.5.7__py3-none-any.whl → 1.5.8__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.

Potentially problematic release.


This version of python-terminusgps might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-terminusgps
3
- Version: 1.5.7
3
+ Version: 1.5.8
4
4
  Summary: Provides abstractions/utilities for working with Wialon API, Authorize.NET API, AWS API, and more.
5
5
  Project-URL: Documentation, https://app.terminusgps.com/docs/apps/python-terminusgps/index.html
6
6
  Project-URL: Repository, https://github.com/terminusgps/python-terminusgps
@@ -4,12 +4,16 @@ terminusgps/authorizenet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
4
4
  terminusgps/authorizenet/auth.py,sha256=zITSQMH8F-3vw-lDQRbuR2s9AVlGqbOyyFo0zqU00qU,870
5
5
  terminusgps/aws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  terminusgps/aws/secrets.py,sha256=kgRA77rs0mD4berWRLkPtJLOe4Grf--o5f8NzwQqXCk,360
7
+ terminusgps/openstreetmap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ terminusgps/openstreetmap/polyline.py,sha256=GHle6UWiHt-HQJ9CXxKG9Z1lr7yXCq_09dHc8IAYP6Y,104
9
+ terminusgps/openstreetmap/renderer.py,sha256=vYvWfdBJAo4vUJlzHzjAaKwISz492-ADKgcZ4Gbabbs,76
10
+ terminusgps/openstreetmap/session.py,sha256=GqDzrA_DkNN0UYcZgRFE4EQ78S6PEbdTkBSB0hyJt3A,1697
7
11
  terminusgps/wialon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
12
  terminusgps/wialon/constants.py,sha256=dsQaNt3TIjIZbr_m94KmBGFdrqe6HER2r6lol3X8QpU,2802
9
13
  terminusgps/wialon/errors.py,sha256=SV9pVwU6FZ_zGlGP6zJN6aLE2auF4TfHFISQLiPMKrI,1758
10
14
  terminusgps/wialon/flags.py,sha256=-OoH-eZM54yjRqxsAXL8VImdQu_7C0OAxCrFqaCEuko,13510
11
15
  terminusgps/wialon/session.py,sha256=x5aXxqLcBe4e0Zj3enUvWd1_Ufmd_MxXInC_d_GMn3E,9446
12
- terminusgps/wialon/utils.py,sha256=J8V2F-QDMsLD5x2OhCYI2lnZZdgqKboMve5XJD7Qt30,1877
16
+ terminusgps/wialon/utils.py,sha256=PMtEaRB9RjdDgWWzHPRnw3Gnrv-DgjywutTCIw1S7_c,2127
13
17
  terminusgps/wialon/items/__init__.py,sha256=3BVthghekMvhMQSzQgBMlD_phxmKSmp3Zvmo-z0O8Bs,211
14
18
  terminusgps/wialon/items/base.py,sha256=MN4FG6U1nWkYAjNfXQJRVrWJoiW4Y64tyqxUO0mhv_w,6593
15
19
  terminusgps/wialon/items/resource.py,sha256=ADjGsQaCqD6Y3_AaD8vLgYzGaMK69MpxCZojnylS4GE,815
@@ -18,7 +22,10 @@ terminusgps/wialon/items/route.py,sha256=qOHPN_rejwiGqvwWzlwmUIAIyc3lKavCalf8ki6
18
22
  terminusgps/wialon/items/unit.py,sha256=tLAWPfHUUS6_Feh1aYBMFPgyuGlSiAnfumJJmGt3bKw,4662
19
23
  terminusgps/wialon/items/unit_group.py,sha256=1yc7ldPIgGbtiTj0djRDWmt6Q9K_VT9sxOaioasbbLY,5212
20
24
  terminusgps/wialon/items/user.py,sha256=bkcMw_YiocaMuhP_pBfB7apjAZwnsOzGScnGkn8Ybbw,6107
21
- python_terminusgps-1.5.7.dist-info/METADATA,sha256=nY0ZeyVuZ4mUV82NrlzNEXNbLQ-kpDUJW8Y1vvFAAOM,882
22
- python_terminusgps-1.5.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- python_terminusgps-1.5.7.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
24
- python_terminusgps-1.5.7.dist-info/RECORD,,
25
+ terminusgps/wialon/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ terminusgps/wialon/maps/layers.py,sha256=K_uxQjRG5Y7WRCpSL5RbYKJFyE87zgYuP9MdoBqgHEU,1763
27
+ terminusgps/wialon/maps/renderer.py,sha256=AusrPT7KXG2yn6E3Ls4DOAJEPANdL7548ZnjHFSmP9Y,5334
28
+ python_terminusgps-1.5.8.dist-info/METADATA,sha256=UDfapsi2DCVaBF5ToB-IXuuE4IG6VEvf74Y11Qkln-k,882
29
+ python_terminusgps-1.5.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ python_terminusgps-1.5.8.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
31
+ python_terminusgps-1.5.8.dist-info/RECORD,,
File without changes
@@ -0,0 +1,7 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class OpenStreetMapPolyline:
6
+ key: str
7
+ value: str
@@ -0,0 +1,3 @@
1
+ class OpenStreetMapRenderer:
2
+ def __init__(self) -> None:
3
+ return
@@ -0,0 +1,54 @@
1
+ import os
2
+ import requests
3
+ from urllib.parse import urlencode
4
+
5
+
6
+ class OpenStreetMapSession:
7
+ def __init__(self, client_id: str, redirect_uri: str, scopes: list[str]) -> None:
8
+ self.client_id = client_id
9
+ self.redirect_uri = redirect_uri
10
+ self.scopes = scopes
11
+ self.base_token_url = "https://master.apis.dev.openstreetmap.org/oauth2/token?"
12
+ self.base_auth_url = (
13
+ "https://master.apis.dev.openstreetmap.org/oauth2/authorize?"
14
+ )
15
+
16
+ def generate_auth_url(self) -> str:
17
+ params = urlencode(
18
+ {
19
+ "response_type": "code",
20
+ "client_id": self.client_id,
21
+ "redirect_uri": self.redirect_uri,
22
+ "scope": "%20".join(self.scopes),
23
+ }
24
+ )
25
+ return self.base_auth_url + params
26
+
27
+ def get_token(self, auth_code: str, client_secret: str) -> str | None:
28
+ params = urlencode(
29
+ {
30
+ "grant_type": "authorization_code",
31
+ "code": auth_code,
32
+ "redirect_uri": self.redirect_uri,
33
+ "client_id": self.client_id,
34
+ "client_secret": client_secret,
35
+ }
36
+ )
37
+ response = requests.post(self.base_token_url + params).json()
38
+ self.scopes = [response.get("scope").split(" ")]
39
+ return response.get("access_token")
40
+
41
+
42
+ def main() -> None:
43
+ scopes = os.getenv("OSM_SCOPES").split(" ")
44
+ session = OpenStreetMapSession(
45
+ client_id=os.getenv("OSM_CLIENT_ID"),
46
+ redirect_uri=os.getenv("OSM_REDIRECT_URI"),
47
+ scopes=scopes,
48
+ )
49
+ print(f"{session.generate_auth_url() = }")
50
+ return
51
+
52
+
53
+ if __name__ == "__main__":
54
+ main()
File without changes
@@ -0,0 +1,49 @@
1
+ from terminusgps.wialon.maps.renderer import WialonMapRenderer
2
+
3
+
4
+ class WialonMapLayerBase:
5
+ def __init__(self, renderer: WialonMapRenderer, name: str) -> None:
6
+ self.renderer = renderer
7
+ self.name = name
8
+ self.bounds = dict()
9
+
10
+ def __str__(self) -> str:
11
+ return self.name
12
+
13
+ def delete_layer(self) -> None:
14
+ self.renderer.session.wialon_api.render_remove_layer(**{"layerName": self.name})
15
+
16
+ def create_layer(self, data: list[dict], flags: int = 0x1) -> None:
17
+ raise NotImplementedError("Subclasses must implement this method")
18
+
19
+
20
+ class WialonMapLayerGeofence(WialonMapLayerBase):
21
+ def create_layer(self, data: list[dict], flags: int = 0x1) -> None:
22
+ response = self.renderer.session.wialon_api.render_create_zones_layer(
23
+ **{"layerName": self.name, "flags": flags, "zones": data}
24
+ )
25
+ self.bounds = {
26
+ "min_lat": response.get("bounds")[0],
27
+ "min_lon": response.get("bounds")[1],
28
+ "max_lat": response.get("bounds")[2],
29
+ "max_lon": response.get("bounds")[3],
30
+ }
31
+
32
+
33
+ class WialonMapLayerPoi(WialonMapLayerBase):
34
+ def create_layer(self, data: list[dict], flags: int = 0x1) -> None:
35
+ response = self.renderer.session.wialon_api.render_create_poi_layer(
36
+ **{"layerName": self.name, "flags": flags, "pois": data}
37
+ )
38
+ self.bounds = {
39
+ "min_lat": response.get("bounds")[0],
40
+ "min_lon": response.get("bounds")[1],
41
+ "max_lat": response.get("bounds")[2],
42
+ "max_lon": response.get("bounds")[3],
43
+ }
44
+
45
+
46
+ class WialonMapLayerTrack(WialonMapLayerBase):
47
+ def __init__(self, **kwargs) -> None:
48
+ self.units = []
49
+ return super().__init__(**kwargs)
@@ -0,0 +1,110 @@
1
+ from django.conf import ImproperlyConfigured, settings
2
+
3
+ from terminusgps.wialon.session import WialonSession
4
+
5
+
6
+ class WialonMapRenderer:
7
+ def __init__(
8
+ self, sid: str | None = None, gis_host: str = "hst-api.wialon.com"
9
+ ) -> None:
10
+ if not hasattr(settings, "WIALON_TOKEN"):
11
+ raise ImproperlyConfigured("'WIALON_TOKEN' setting is required.")
12
+
13
+ self.host = gis_host
14
+ self.layers = []
15
+ self.session = WialonSession(sid=sid)
16
+
17
+ @property
18
+ def total_layers(self) -> int:
19
+ return len(self.layers)
20
+
21
+ def get_events(self):
22
+ return self.session.wialon_api.avl_evts()
23
+
24
+ def toggle_layer(self, name: str, enabled: bool = True) -> None:
25
+ self.session.wialon_api.render_enable_layer(
26
+ **{"layerName": name, "enable": enabled}
27
+ )
28
+
29
+ def delete_all_layers(self) -> None:
30
+ self.session.wialon_api.render_remove_all_layers({})
31
+ self.layers = []
32
+
33
+ def get_tiles_url(self, x: int, y: int, z: int) -> str:
34
+ MIN_ZOOM, MAX_ZOOM = 2, 17
35
+ z = min(max(z, MIN_ZOOM), MAX_ZOOM)
36
+ return f"http://{self.host}/avl_render/{x}_{y}_{z}/{self.session.id}.png"
37
+
38
+ def update_locale(
39
+ self,
40
+ tz: int,
41
+ lang: str = "en",
42
+ flags: int = 1,
43
+ date_fmt: str = "%m-%E-%Y %H:%M:%S",
44
+ density: int = 256 * 256,
45
+ ) -> None:
46
+ """
47
+ Updates the renderer locale.
48
+
49
+
50
+ Date Format:
51
+
52
+ +-----------+------------------------------------------------------------------------+
53
+ | Parameter | Description |
54
+ +===========+========================================================================+
55
+ | ``%H`` | The hour of the day with leading zero if required ("00" to "23") |
56
+ +-----------+------------------------------------------------------------------------+
57
+ | ``%B`` | The full month name ("January" to "December") |
58
+ +-----------+------------------------------------------------------------------------+
59
+ | ``%b`` | Abbreviated month name ("Jan" to "Dec") |
60
+ +-----------+------------------------------------------------------------------------+
61
+ | ``%m`` | The month of the year with leading zero if required ("01" to "12") |
62
+ +-----------+------------------------------------------------------------------------+
63
+ | ``%l`` | The month of the year between 1-12 ("1" to "12") |
64
+ +-----------+------------------------------------------------------------------------+
65
+ | ``%P`` | Format Persian calendar ("01 Farvardin 1392 00:00:00") |
66
+ +-----------+------------------------------------------------------------------------+
67
+ | ``%A`` | The full day name ("Monday" to "Sunday") |
68
+ +-----------+------------------------------------------------------------------------+
69
+ | ``%a`` | Abbreviated day name ("Mon" to "Sun") |
70
+ +-----------+------------------------------------------------------------------------+
71
+ | ``%E`` | The day of the month with a leading zero if required ("01" to "31") |
72
+ +-----------+------------------------------------------------------------------------+
73
+ | ``%e`` | The day of the month between 1 and 31 ("1" to "31") |
74
+ +-----------+------------------------------------------------------------------------+
75
+ | ``%I`` | The hour of the day with leading zero if required ("01" to "12") |
76
+ +-----------+------------------------------------------------------------------------+
77
+ | ``%M`` | The minute of the hour with leading zero if required ("00" to "59") |
78
+ +-----------+------------------------------------------------------------------------+
79
+ | ``%S`` | The seconds of the minute with leading zero if required ("00" to "59") |
80
+ +-----------+------------------------------------------------------------------------+
81
+ | ``%p`` | Displays the A.M./P.M. designator ("AM" or "PM") |
82
+ +-----------+------------------------------------------------------------------------+
83
+ | ``%Y`` | The full four digit year ("1999" or "2000") |
84
+ +-----------+------------------------------------------------------------------------+
85
+ | ``%y`` | The year as a two digit number ("99" or "00") |
86
+ +-----------+------------------------------------------------------------------------+
87
+
88
+ """
89
+ self.session.wialon_api.render_set_locale(
90
+ **{
91
+ "tzOffset": tz,
92
+ "language": lang,
93
+ "flags": flags,
94
+ "formatDate": date_fmt,
95
+ "density": density,
96
+ }
97
+ )
98
+
99
+
100
+ def main() -> None:
101
+ from terminusgps.wialon.maps.layers import WialonMapLayerPoi
102
+
103
+ with WialonSession() as session:
104
+ renderer = WialonMapRenderer(session.id)
105
+ layer = WialonMapLayerPoi(renderer, "terminusgps_office")
106
+ return
107
+
108
+
109
+ if __name__ == "__main__":
110
+ main()
@@ -38,10 +38,10 @@ def get_id_from_iccid(iccid: str, session: WialonSession) -> str | None:
38
38
  **{
39
39
  "spec": {
40
40
  "itemsType": "avl_unit",
41
- "propName": "sys_unique_id",
42
- "propValueMask": f"={iccid}",
43
- "sortType": "sys_unique_id",
44
- "propType": "property",
41
+ "propName": "rel_admin_field_value",
42
+ "propValueMask": str(iccid),
43
+ "sortType": "admin_fields",
44
+ "propType": "adminfield",
45
45
  "or_logic": 0,
46
46
  },
47
47
  "force": 0,
@@ -50,6 +50,18 @@ def get_id_from_iccid(iccid: str, session: WialonSession) -> str | None:
50
50
  "to": 0,
51
51
  }
52
52
  )
53
+ print(f"{response = }")
53
54
  if response.get("totalItemsCount", 0) != 1:
54
55
  return None
55
56
  return response["items"][0].get("id")
57
+
58
+
59
+ def main() -> None:
60
+ with WialonSession() as session:
61
+ wialon_id = get_id_from_iccid("89015809000307608963", session)
62
+ print(f"{wialon_id = }")
63
+ return
64
+
65
+
66
+ if __name__ == "__main__":
67
+ main()