grawgo 2.0.0__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.
__init__.py ADDED
File without changes
grawgo/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ import logging
2
+ from os import getenv
3
+
4
+ logging.basicConfig(
5
+ level=getattr(
6
+ logging, getenv(key="LOG_LEVEL", default="INFO").upper(), logging.INFO
7
+ ),
8
+ format="%(levelname)s: %(message)s",
9
+ )
grawgo/api.py ADDED
@@ -0,0 +1,179 @@
1
+ from logging import info
2
+ from typing import Any
3
+ from urllib.parse import urlparse
4
+
5
+ from requests import Response, get, post
6
+
7
+
8
+ class Api:
9
+ def __init__(
10
+ self,
11
+ base_url: str,
12
+ username: str = "",
13
+ password: str = "",
14
+ logging: bool = False,
15
+ ) -> None:
16
+ self.base_url: str = base_url
17
+ self.auth: tuple[str, str] = (username, password)
18
+ self.logging: bool = logging
19
+ self.verify_https: bool = urlparse(self.base_url).hostname != "localhost"
20
+
21
+ def log(self, message: str | dict[str, Any]) -> None:
22
+ if self.logging:
23
+ if isinstance(message, dict) and "password" in message:
24
+ message = {**message, "password": "[REDACTED]"}
25
+
26
+ info(msg=message)
27
+
28
+ def log_response(self, response: Response) -> None:
29
+ if self.logging and not response.ok:
30
+ info(msg=response.status_code)
31
+ info(msg=response.content)
32
+
33
+ def get(self, path: str, authorized: bool = True) -> Response:
34
+ self.log(message=f"GET {self.base_url}/{path}")
35
+
36
+ auth = None
37
+ if authorized:
38
+ auth = self.auth
39
+
40
+ response: Response = get(
41
+ url=f"{self.base_url}/{path}",
42
+ headers={
43
+ "Accept": "application/json",
44
+ },
45
+ auth=auth,
46
+ verify=self.verify_https,
47
+ )
48
+
49
+ self.log_response(response=response)
50
+ return response
51
+
52
+ def post(self, path: str, json: Any) -> Response:
53
+ # TODO: fix for list in json instead of dict
54
+ # sanitized_json: dict[str, Any] = {**json}
55
+ # if "password" in sanitized_json:
56
+ # sanitized_json["password"] = "[REDACTED]"
57
+ # self.log(message=f"POST {self.base_url}/{path} {sanitized_json}")
58
+
59
+ response: Response = post(
60
+ url=f"{self.base_url}/{path}",
61
+ headers={"Accept": "application/json", "Content-Type": "application/json"},
62
+ auth=self.auth,
63
+ json=json,
64
+ verify=self.verify_https,
65
+ )
66
+
67
+ self.log_response(response=response)
68
+ return response
69
+
70
+ def status(self) -> Response:
71
+ return self.get(path="status", authorized=False)
72
+
73
+ def user_self(self) -> Response:
74
+ return self.get(path="user/self")
75
+
76
+ def user_self_stations(self) -> list[Any]:
77
+ return self.user_self().json()["data"]["stations"]
78
+
79
+ def user_self_first_station(self):
80
+ return self.user_self_stations()[0]
81
+
82
+ def create_user(self, email: str, password: str, role: str, name: str) -> Response:
83
+ return self.post(
84
+ path="user",
85
+ json={
86
+ "email": email,
87
+ "password": password,
88
+ "role": role,
89
+ "name": name,
90
+ },
91
+ )
92
+
93
+ def create_station(
94
+ self,
95
+ name: str,
96
+ operation_type: str,
97
+ wmo_id: int,
98
+ latitude: float,
99
+ longitude: float,
100
+ altitude: float,
101
+ ) -> Response:
102
+ return self.post(
103
+ path="station",
104
+ json={
105
+ "name": name,
106
+ "type": operation_type,
107
+ "wmo_id": wmo_id,
108
+ "latitude": latitude,
109
+ "longitude": longitude,
110
+ "altitude": altitude,
111
+ },
112
+ )
113
+
114
+ def create_flight(
115
+ self,
116
+ station_id: int,
117
+ status: str,
118
+ sonde_serial: str,
119
+ set_frequency: float,
120
+ sonde_firmware_version: str,
121
+ ) -> Response:
122
+ return self.post(
123
+ path="flight",
124
+ json={
125
+ "station_id": station_id,
126
+ "status": status,
127
+ "sonde_serial": sonde_serial,
128
+ "set_frequency": set_frequency,
129
+ "sonde_firmware_version": sonde_firmware_version,
130
+ },
131
+ )
132
+
133
+ def create_measurement(
134
+ self,
135
+ flight_id: int,
136
+ time_after_launch: int,
137
+ utc_time: str,
138
+ pressure: float,
139
+ temperature: float,
140
+ humidity: float,
141
+ wind_speed: float,
142
+ wind_direction: float,
143
+ latitude: float,
144
+ longitude: float,
145
+ altitude: float,
146
+ vertical_speed: float,
147
+ geo_potential: float,
148
+ dew_point: float,
149
+ elevation: float,
150
+ azimuth: float,
151
+ distance: float,
152
+ ) -> Response:
153
+ return self.post(
154
+ path="measurement",
155
+ json=[
156
+ {
157
+ "flight_id": flight_id,
158
+ "time_after_launch": time_after_launch,
159
+ "utc_time": utc_time,
160
+ "pressure": pressure,
161
+ "temperature": temperature,
162
+ "humidity": humidity,
163
+ "wind_speed": wind_speed,
164
+ "wind_direction": wind_direction,
165
+ "latitude": latitude,
166
+ "longitude": longitude,
167
+ "altitude": altitude,
168
+ "vertical_speed": vertical_speed,
169
+ "geo_potential": geo_potential,
170
+ "dew_point": dew_point,
171
+ "elevation": elevation,
172
+ "azimuth": azimuth,
173
+ "distance": distance,
174
+ },
175
+ ],
176
+ )
177
+
178
+ def attach_station_to_user(self, user_id: int, station_id: int) -> Response:
179
+ return self.post(path=f"user/{user_id}/attachStation/{station_id}", json={})
grawgo/py.typed ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: grawgo
3
+ Version: 2.0.0
4
+ Summary: A python lib to use the grawGo api
5
+ Author-email: Niklas Wildenburg <niklas.wildenburg@graw.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/GrawRadiosondes/grawgo-python-api
8
+ Project-URL: Bug Tracker, https://github.com/GrawRadiosondes/grawgo-python-api/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.14
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests~=2.34.0
15
+ Dynamic: license-file
16
+
17
+ # grawGo API
18
+
19
+ ## Release
20
+
21
+ 1. `ruff format`
22
+ 2. Bump version in [pyproject.toml](pyproject.toml)
23
+ 3. Commit
24
+ 4. Apply SemVer tag
25
+ 5. Push commit and tag
@@ -0,0 +1,9 @@
1
+ __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ grawgo/__init__.py,sha256=WqkJBewYxX-SGGMGv3kFESnTzQCCg4XmAIsMLtBiPus,207
3
+ grawgo/api.py,sha256=d9TVnBTli4_eYL7rVwp6tAreMUixVwn595Iwdy8rVbA,5440
4
+ grawgo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ grawgo-2.0.0.dist-info/licenses/LICENSE,sha256=497WkD2tIov9SXAD-r8HV9AfC6o1WimjUay0UPu2w9M,1073
6
+ grawgo-2.0.0.dist-info/METADATA,sha256=_5IBP-DeVOFN3x90OdGlkDnErvt_lj3WwCp5zfMm2HQ,724
7
+ grawgo-2.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ grawgo-2.0.0.dist-info/top_level.txt,sha256=vvf4tXSUGiLQGs5uuvLgx9MVr8owt3aXwBbblRQUkFE,16
9
+ grawgo-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GRAW Radiosondes
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.
@@ -0,0 +1,2 @@
1
+ __init__
2
+ grawgo