weiche 0.9.1.dev1__tar.gz → 0.10.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.
Files changed (35) hide show
  1. {weiche-0.9.1.dev1 → weiche-0.10.0}/.github/workflows/ci.yml +3 -5
  2. {weiche-0.9.1.dev1 → weiche-0.10.0}/.gitignore +1 -0
  3. weiche-0.10.0/.mdlrc +7 -0
  4. {weiche-0.9.1.dev1 → weiche-0.10.0}/PKG-INFO +33 -5
  5. {weiche-0.9.1.dev1 → weiche-0.10.0}/README.md +32 -4
  6. {weiche-0.9.1.dev1 → weiche-0.10.0}/pyproject.toml +4 -9
  7. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/api/asynchronous.py +28 -12
  8. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/api/synchronous.py +27 -11
  9. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/schiene.py +2 -2
  10. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/version.py +2 -2
  11. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche.egg-info/PKG-INFO +33 -5
  12. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche.egg-info/SOURCES.txt +1 -0
  13. {weiche-0.9.1.dev1 → weiche-0.10.0}/.coveragerc +0 -0
  14. {weiche-0.9.1.dev1 → weiche-0.10.0}/.flake8 +0 -0
  15. {weiche-0.9.1.dev1 → weiche-0.10.0}/.pre-commit-config.yaml +0 -0
  16. {weiche-0.9.1.dev1 → weiche-0.10.0}/LICENSE +0 -0
  17. {weiche-0.9.1.dev1 → weiche-0.10.0}/MANIFEST.in +0 -0
  18. {weiche-0.9.1.dev1 → weiche-0.10.0}/setup.cfg +0 -0
  19. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/py.typed +0 -0
  20. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/__init__.py +0 -0
  21. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/api/__init__.py +0 -0
  22. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/api/base.py +0 -0
  23. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/api/parser.py +0 -0
  24. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/const.py +0 -0
  25. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/formatter.py +0 -0
  26. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/objects.py +0 -0
  27. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/tests/__init__.py +0 -0
  28. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/tests/test_asynchronous.py +0 -0
  29. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/tests/test_schiene.py +0 -0
  30. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche/tests/test_synchronous.py +0 -0
  31. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche.egg-info/dependency_links.txt +0 -0
  32. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche.egg-info/requires.txt +0 -0
  33. {weiche-0.9.1.dev1 → weiche-0.10.0}/src/weiche.egg-info/top_level.txt +0 -0
  34. {weiche-0.9.1.dev1 → weiche-0.10.0}/tox.ini +0 -0
  35. {weiche-0.9.1.dev1 → weiche-0.10.0}/utils/pre-commit +0 -0
@@ -6,7 +6,7 @@ jobs:
6
6
  runs-on: ubuntu-latest
7
7
  strategy:
8
8
  matrix:
9
- python-version: ['3.11']
9
+ python-version: ['3.10', '3.11', '3.12', '3.13']
10
10
  steps:
11
11
  - uses: actions/checkout@v3
12
12
  - uses: actions/setup-python@v4.5.0
@@ -15,8 +15,8 @@ jobs:
15
15
  - name: Install dependencies
16
16
  run: |
17
17
  python -m pip install --upgrade pip
18
- python -m pip install --use-pep517 pytest-cov pytest-random pytest-remove-stale-bytecode flake8 pycodestyle pydocstyle Sphinx sphinx_rtd_theme
19
- python -m pip install .
18
+ python -m pip install --use-pep517 pytest-cov pytest-random pytest-remove-stale-bytecode flake8 pycodestyle pydocstyle
19
+ python -m pip install .[test]
20
20
  - name: Run unittest
21
21
  run: pytest -v --random --cov=src/weiche --cov-report=term
22
22
  - name: flake8
@@ -25,5 +25,3 @@ jobs:
25
25
  run: pycodestyle -v --first src
26
26
  - name: pydocstyle
27
27
  run: pydocstyle -v --match='(?!test_|version)(.*)?\.py' src
28
- - name: build docs
29
- run: sphinx-build -M html docs/source doc/build
@@ -12,3 +12,4 @@ htmlcov
12
12
  *requirement*.txt
13
13
  *.pickle
14
14
  .*venv/
15
+ src/weiche/version.py
weiche-0.10.0/.mdlrc ADDED
@@ -0,0 +1,7 @@
1
+ # Auto-generated from https://github.com/xcnt/xcnt-gardener/blob/main/templates/common/.mdlrc
2
+
3
+ # See set of available rules here: https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
4
+ rules "MD001", "MD002", "MD003", "MD009", "MD012", "MD018", "MD019", "MD022", "MD023", "MD025", "MD026", "MD041", "MD047"
5
+
6
+ # header style
7
+ rule "MD003", :style => atx
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: weiche
3
- Version: 0.9.1.dev1
3
+ Version: 0.10.0
4
4
  Summary: A wrapper around the DB Website API for querying train connections.
5
5
  Author-email: Christoph Brand <christoph+pypi@brand.rest>
6
6
  License: MIT License
@@ -109,12 +109,22 @@ api.search_connections(
109
109
  )
110
110
  ```
111
111
 
112
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
113
+
114
+ ```python
115
+ from weiche import SynchronousApi
116
+
117
+ api = SynchronousApi(proxy="192.168.0.1:8888")
118
+ ```
119
+
112
120
  <details>
113
121
  <summary>Response from Synchronous API</summary>
114
122
 
115
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
123
+ The return format is an object which can also be found in the
124
+ [objects.py](./src/weiche/objects.py) file.
116
125
 
117
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
126
+ Look for the [`Connection`](./src/weiche/objects.py#L175) class
127
+ and see the API definition there.
118
128
 
119
129
  </details>
120
130
 
@@ -143,12 +153,22 @@ async def search():
143
153
  asyncio.get_event_loop().run_until_complete(search())
144
154
  ```
145
155
 
156
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
157
+
158
+ ```python
159
+ from weiche import AsynchronousApi
160
+
161
+ api = AsynchronousApi(proxy="192.168.0.1:8888")
162
+ ```
163
+
146
164
  <details>
147
165
  <summary>Response from Asynchronous API</summary>
148
166
 
149
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
167
+ The return format is an object which can also be found in the
168
+ [objects.py](./src/weiche/objects.py) file.
150
169
 
151
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
170
+ Look for the [`Connection`](./src/weiche/objects.py#L175)
171
+ class and see the API definition there.
152
172
 
153
173
  </details>
154
174
 
@@ -160,6 +180,14 @@ from weiche import Schiene
160
180
  Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
161
181
  ```
162
182
 
183
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
184
+
185
+ ```python
186
+ from weiche import Schiene
187
+
188
+ api = Schiene(proxy="192.168.0.1:8888")
189
+ ```
190
+
163
191
  <details>
164
192
  <summary>Response from Schiene Layer</summary>
165
193
 
@@ -53,12 +53,22 @@ api.search_connections(
53
53
  )
54
54
  ```
55
55
 
56
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
57
+
58
+ ```python
59
+ from weiche import SynchronousApi
60
+
61
+ api = SynchronousApi(proxy="192.168.0.1:8888")
62
+ ```
63
+
56
64
  <details>
57
65
  <summary>Response from Synchronous API</summary>
58
66
 
59
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
67
+ The return format is an object which can also be found in the
68
+ [objects.py](./src/weiche/objects.py) file.
60
69
 
61
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
70
+ Look for the [`Connection`](./src/weiche/objects.py#L175) class
71
+ and see the API definition there.
62
72
 
63
73
  </details>
64
74
 
@@ -87,12 +97,22 @@ async def search():
87
97
  asyncio.get_event_loop().run_until_complete(search())
88
98
  ```
89
99
 
100
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
101
+
102
+ ```python
103
+ from weiche import AsynchronousApi
104
+
105
+ api = AsynchronousApi(proxy="192.168.0.1:8888")
106
+ ```
107
+
90
108
  <details>
91
109
  <summary>Response from Asynchronous API</summary>
92
110
 
93
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
111
+ The return format is an object which can also be found in the
112
+ [objects.py](./src/weiche/objects.py) file.
94
113
 
95
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
114
+ Look for the [`Connection`](./src/weiche/objects.py#L175)
115
+ class and see the API definition there.
96
116
 
97
117
  </details>
98
118
 
@@ -104,6 +124,14 @@ from weiche import Schiene
104
124
  Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
105
125
  ```
106
126
 
127
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
128
+
129
+ ```python
130
+ from weiche import Schiene
131
+
132
+ api = Schiene(proxy="192.168.0.1:8888")
133
+ ```
134
+
107
135
  <details>
108
136
  <summary>Response from Schiene Layer</summary>
109
137
 
@@ -32,13 +32,8 @@ dynamic = ['version']
32
32
  [tools.setuptools]
33
33
  package-dir = {'' = 'src'}
34
34
 
35
- [tools.setuptools.dynamic]
36
- version = {attr = 'weiche.version.version'}
37
-
38
- [tool.setuptools_scm]
39
- write_to = 'src/weiche/version.py'
40
- version_scheme = 'python-simplified-semver'
41
- local_scheme = 'no-local-version'
35
+ [tool.setuptools.dynamic]
36
+ version = { attr = "setuptools_scm.get_version" }
42
37
 
43
38
  [project.urls]
44
39
  'Homepage' = 'https://github.com/cbrand/weiche'
@@ -68,10 +63,10 @@ force_grid_wrap=0
68
63
  known_first_party="xcnt"
69
64
 
70
65
  [tool.semantic_release]
71
- version_variables = ["setup.py:__version__"]
66
+ version_variables = ["src/weiche/version.py:__version__"]
72
67
  commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
73
68
  commit_parser = "angular"
74
- build_command = "python setup.py sdist bdist_wheel"
69
+ build_command = "python -m build --sdist --wheel ."
75
70
 
76
71
  [tool.semantic_release.branches.main]
77
72
  match = "(main|master)"
@@ -1,5 +1,6 @@
1
1
  from datetime import datetime
2
2
  from http import HTTPStatus
3
+ import asyncio
3
4
 
4
5
  import aiohttp
5
6
 
@@ -10,9 +11,10 @@ from weiche.objects import Association, Connection, ConnectionRequest, Location
10
11
 
11
12
 
12
13
  class AsynchronousApi(BaseApi):
13
- def __init__(self, base_url: str = DEFAULT_BASE_URL):
14
+ def __init__(self, base_url: str = DEFAULT_BASE_URL, proxy: str | None = None) -> None:
14
15
  super().__init__(base_url)
15
- self.session = aiohttp.ClientSession()
16
+ proxy = proxy or None
17
+ self.session = aiohttp.ClientSession(proxy=proxy)
16
18
 
17
19
  async def get_travel_associations(self) -> list[Association]:
18
20
  async with self.session.get(self.travel_associations_url) as response:
@@ -20,16 +22,23 @@ class AsynchronousApi(BaseApi):
20
22
  return parse_associations(await response.json())
21
23
 
22
24
  async def search_locations(self, query: str, limit: int = 10, location_type: str = "ALL") -> list[Location]:
23
- async with self.session.get(
24
- self.locations_url,
25
- params=self.get_locations_params(
26
- query=query,
27
- limit=limit,
28
- location_type=location_type,
29
- ),
30
- ) as response:
31
- assert response.status == HTTPStatus.OK, f"Error: {response.status}"
32
- return parse_locations(await response.json())
25
+ tries = 0
26
+ while True:
27
+ async with self.session.get(
28
+ self.locations_url,
29
+ params=self.get_locations_params(
30
+ query=query,
31
+ limit=limit,
32
+ location_type=location_type,
33
+ ),
34
+ ) as response:
35
+ if response.status == HTTPStatus.TOO_MANY_REQUESTS:
36
+ tries += 1
37
+ await asyncio.sleep(tries)
38
+ continue
39
+
40
+ assert response.status == HTTPStatus.OK, f"Error: {response.status}"
41
+ return parse_locations(await response.json())
33
42
 
34
43
  async def search_connections(
35
44
  self,
@@ -45,12 +54,19 @@ class AsynchronousApi(BaseApi):
45
54
 
46
55
  async def search_connections_ext(self, request: ConnectionRequest, limit: int = 10) -> list[Connection]:
47
56
  responses: list[Connection] = []
57
+ tries = 0
48
58
  while len(responses) < limit:
49
59
  request_params = self.get_connections_ext_params(request)
50
60
  async with self.session.post(
51
61
  self.connections_url,
52
62
  json=request_params,
53
63
  ) as response:
64
+ if response.status == HTTPStatus.TOO_MANY_REQUESTS:
65
+ tries += 1
66
+ await asyncio.sleep(tries)
67
+ continue
68
+ tries = 0
69
+
54
70
  assert response.status in (
55
71
  HTTPStatus.OK,
56
72
  HTTPStatus.CREATED,
@@ -1,6 +1,7 @@
1
1
  from datetime import datetime
2
2
  from http import HTTPStatus
3
3
 
4
+ import time
4
5
  import requests
5
6
 
6
7
  from weiche.api.base import BaseApi
@@ -10,9 +11,11 @@ from weiche.objects import Association, Connection, ConnectionRequest, Location
10
11
 
11
12
 
12
13
  class SynchronousApi(BaseApi):
13
- def __init__(self, base_url: str = DEFAULT_BASE_URL):
14
+ def __init__(self, base_url: str = DEFAULT_BASE_URL, proxy: str | None = None) -> None:
14
15
  super().__init__(base_url)
15
16
  self.session = requests.Session()
17
+ if proxy:
18
+ self.session.proxies = {"http": proxy, "https": proxy}
16
19
 
17
20
  def get_travel_associations(self) -> list[Association]:
18
21
  response = self.session.get(self.travel_associations_url)
@@ -20,16 +23,22 @@ class SynchronousApi(BaseApi):
20
23
  return parse_associations(response.json())
21
24
 
22
25
  def search_locations(self, query: str, limit: int = 10, location_type: str = "ALL") -> list[Location]:
23
- response = self.session.get(
24
- self.locations_url,
25
- params=self.get_locations_params(
26
- query=query,
27
- limit=limit,
28
- location_type=location_type,
29
- ),
30
- )
31
- assert response.status_code == HTTPStatus.OK, f"Error: {response.status_code}"
32
- return parse_locations(response.json())
26
+ tries = 0
27
+ while True:
28
+ tries += 1
29
+ response = self.session.get(
30
+ self.locations_url,
31
+ params=self.get_locations_params(
32
+ query=query,
33
+ limit=limit,
34
+ location_type=location_type,
35
+ ),
36
+ )
37
+ if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
38
+ time.sleep(tries)
39
+ continue
40
+ assert response.status_code == HTTPStatus.OK, f"Error: {response.status_code}"
41
+ return parse_locations(response.json())
33
42
 
34
43
  def search_connections(
35
44
  self,
@@ -45,12 +54,19 @@ class SynchronousApi(BaseApi):
45
54
 
46
55
  def search_connections_ext(self, request: ConnectionRequest, limit: int = 10) -> list[Connection]:
47
56
  responses: list[Connection] = []
57
+ tries = 0
48
58
  while len(responses) < limit:
49
59
  request_params = self.get_connections_ext_params(request)
50
60
  response = self.session.post(
51
61
  self.connections_url,
52
62
  json=request_params,
53
63
  )
64
+ if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
65
+ tries += 1
66
+ time.sleep(tries)
67
+ continue
68
+ tries = 0
69
+
54
70
  assert response.status_code in (
55
71
  HTTPStatus.OK,
56
72
  HTTPStatus.CREATED,
@@ -88,8 +88,8 @@ def schiene_to_dict(location: Location, index: int) -> SchieneStation:
88
88
 
89
89
 
90
90
  class Schiene:
91
- def __init__(self):
92
- self.api = SynchronousApi()
91
+ def __init__(self, proxy: str | None = None) -> None:
92
+ self.api = SynchronousApi(proxy=proxy)
93
93
 
94
94
  def stations(self, station: str, limit: int = 10) -> list[SchieneStation]:
95
95
  """Find stations for given queries.
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.9.1.dev1'
21
- __version_tuple__ = version_tuple = (0, 9, 1, 'dev1')
20
+ __version__ = version = '0.9.2.dev0'
21
+ __version_tuple__ = version_tuple = (0, 9, 2, 'dev0')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: weiche
3
- Version: 0.9.1.dev1
3
+ Version: 0.10.0
4
4
  Summary: A wrapper around the DB Website API for querying train connections.
5
5
  Author-email: Christoph Brand <christoph+pypi@brand.rest>
6
6
  License: MIT License
@@ -109,12 +109,22 @@ api.search_connections(
109
109
  )
110
110
  ```
111
111
 
112
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
113
+
114
+ ```python
115
+ from weiche import SynchronousApi
116
+
117
+ api = SynchronousApi(proxy="192.168.0.1:8888")
118
+ ```
119
+
112
120
  <details>
113
121
  <summary>Response from Synchronous API</summary>
114
122
 
115
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
123
+ The return format is an object which can also be found in the
124
+ [objects.py](./src/weiche/objects.py) file.
116
125
 
117
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
126
+ Look for the [`Connection`](./src/weiche/objects.py#L175) class
127
+ and see the API definition there.
118
128
 
119
129
  </details>
120
130
 
@@ -143,12 +153,22 @@ async def search():
143
153
  asyncio.get_event_loop().run_until_complete(search())
144
154
  ```
145
155
 
156
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
157
+
158
+ ```python
159
+ from weiche import AsynchronousApi
160
+
161
+ api = AsynchronousApi(proxy="192.168.0.1:8888")
162
+ ```
163
+
146
164
  <details>
147
165
  <summary>Response from Asynchronous API</summary>
148
166
 
149
- The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
167
+ The return format is an object which can also be found in the
168
+ [objects.py](./src/weiche/objects.py) file.
150
169
 
151
- Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
170
+ Look for the [`Connection`](./src/weiche/objects.py#L175)
171
+ class and see the API definition there.
152
172
 
153
173
  </details>
154
174
 
@@ -160,6 +180,14 @@ from weiche import Schiene
160
180
  Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
161
181
  ```
162
182
 
183
+ You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
184
+
185
+ ```python
186
+ from weiche import Schiene
187
+
188
+ api = Schiene(proxy="192.168.0.1:8888")
189
+ ```
190
+
163
191
  <details>
164
192
  <summary>Response from Schiene Layer</summary>
165
193
 
@@ -1,6 +1,7 @@
1
1
  .coveragerc
2
2
  .flake8
3
3
  .gitignore
4
+ .mdlrc
4
5
  .pre-commit-config.yaml
5
6
  LICENSE
6
7
  MANIFEST.in
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes