# pytrafikverket
python module for communicating with the swedish trafikverket api
Development and testing done with 3.11
## Code example
```python
from pytrafikverket import TrafikverketTrain, StationInfo
import aiohttp
import asyncio
from datetime import datetime
async def main(loop):
async with aiohttp.ClientSession(loop=loop) as session:
train_api = TrafikverketTrain(session, "api_key_here")
stations = await train_api.async_search_train_stations("kristianstad")
for station in stations:
print(station.name + " " + station.signature)
from_station = await train_api.async_get_train_station("Sölvesborg")
to_station = await train_api.async_get_train_station("Kristianstad C")
product_description = "SJ Regional" # Optional search field
print("from_station_signature: " + from_station.signature)
print("to_station_signature: " + to_station.signature)
train_stop = await train_api.async_get_train_stop(
from_station, to_station, datetime(2022, 4, 11, 12, 57), product_description
)
print(train_stop.get_state())
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
```
## CLI example
<!-- blacken-docs:off -->
```python
trafikverket_cli -key <api_key> -method search-for-station -station "Kristianstad"
trafikverket_cli -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg"
trafikverket_cli -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -train-product "SJ Regional"
trafikverket_cli -key <api_key> -method get-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -date-time "2017-05-19T16:38:00"
trafikverket_cli -key <api_key> -method get-weather -station "Nöbbele"
trafikverket_cli -key <api_key> -method search-for-ferry-route -route "sund"
trafikverket_cli -key <api_key> -method get-ferry-route -route "Adelsöleden"
trafikverket_cli -key <api_key> -method get-next-ferry-stop -from-harbor "Ekerö"
trafikverket_cli -key <api_key> -method get-next-ferry-stop -from-harbor "Furusund" -date-time "2019-12-24T00:00:00"
```
<!-- blacken-docs:on -->
Raw data
{
"_id": null,
"home_page": "https://github.com/gjohansson-ST/pytrafikverket",
"name": "pytrafikverket",
"maintainer": "G Johansson",
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": "goran.johansson@shiftit.se",
"keywords": "trafikverket, api, async, client",
"author": "G Johansson",
"author_email": "goran.johansson@shiftit.se",
"download_url": "https://files.pythonhosted.org/packages/45/30/538878f57307bdde4c422561fb36a4a3e67183b388c0001c6562af3d1815/pytrafikverket-1.1.1.tar.gz",
"platform": null,
"description": "# pytrafikverket\npython module for communicating with the swedish trafikverket api\n\nDevelopment and testing done with 3.11\n\n## Code example\n\n```python\nfrom pytrafikverket import TrafikverketTrain, StationInfo\nimport aiohttp\nimport asyncio\nfrom datetime import datetime\n\n\nasync def main(loop):\n async with aiohttp.ClientSession(loop=loop) as session:\n train_api = TrafikverketTrain(session, \"api_key_here\")\n stations = await train_api.async_search_train_stations(\"kristianstad\")\n for station in stations:\n print(station.name + \" \" + station.signature)\n\n from_station = await train_api.async_get_train_station(\"S\u00f6lvesborg\")\n to_station = await train_api.async_get_train_station(\"Kristianstad C\")\n product_description = \"SJ Regional\" # Optional search field\n print(\"from_station_signature: \" + from_station.signature)\n print(\"to_station_signature: \" + to_station.signature)\n train_stop = await train_api.async_get_train_stop(\n from_station, to_station, datetime(2022, 4, 11, 12, 57), product_description\n )\n print(train_stop.get_state())\n\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main(loop))\n```\n\n## CLI example\n<!-- blacken-docs:off -->\n```python\ntrafikverket_cli -key <api_key> -method search-for-station -station \"Kristianstad\"\ntrafikverket_cli -key <api_key> -method get-next-train-stop -from-station \"Kristianstad C\" -to-station \"S\u00f6lvesborg\"\ntrafikverket_cli -key <api_key> -method get-next-train-stop -from-station \"Kristianstad C\" -to-station \"S\u00f6lvesborg\" -train-product \"SJ Regional\"\ntrafikverket_cli -key <api_key> -method get-train-stop -from-station \"Kristianstad C\" -to-station \"S\u00f6lvesborg\" -date-time \"2017-05-19T16:38:00\"\ntrafikverket_cli -key <api_key> -method get-weather -station \"N\u00f6bbele\"\ntrafikverket_cli -key <api_key> -method search-for-ferry-route -route \"sund\"\ntrafikverket_cli -key <api_key> -method get-ferry-route -route \"Adels\u00f6leden\"\ntrafikverket_cli -key <api_key> -method get-next-ferry-stop -from-harbor \"Eker\u00f6\"\ntrafikverket_cli -key <api_key> -method get-next-ferry-stop -from-harbor \"Furusund\" -date-time \"2019-12-24T00:00:00\"\n```\n<!-- blacken-docs:on -->\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Retrieve values from public API at the Swedish Transport Administration (Trafikverket).",
"version": "1.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/gjohansson-ST/pytrafikverket/issues",
"Changelog": "https://github.com/gjohansson-ST/pytrafikverket/releases",
"Documentation": "https://github.com/gjohansson-ST/pytrafikverket",
"Homepage": "https://github.com/gjohansson-ST/pytrafikverket",
"Repository": "https://github.com/gjohansson-ST/pytrafikverket"
},
"split_keywords": [
"trafikverket",
" api",
" async",
" client"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "75044622c906e8c45f5b269b8a70778e71098a0449374da151130ce7c0d5dcd0",
"md5": "725136b5821d974b9aee4e725f746f7e",
"sha256": "7a73a90f2471a1033a8141d0caaec1f44381b29b6704cd2412a454e553914d0f"
},
"downloads": -1,
"filename": "pytrafikverket-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "725136b5821d974b9aee4e725f746f7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 18825,
"upload_time": "2024-11-22T14:21:19",
"upload_time_iso_8601": "2024-11-22T14:21:19.721351Z",
"url": "https://files.pythonhosted.org/packages/75/04/4622c906e8c45f5b269b8a70778e71098a0449374da151130ce7c0d5dcd0/pytrafikverket-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4530538878f57307bdde4c422561fb36a4a3e67183b388c0001c6562af3d1815",
"md5": "5588db9727b00aeebed8973f59845282",
"sha256": "c9fa37e9f0150b62daadeb10d50717ab6106846b6457335b5af0fa9729e1bac4"
},
"downloads": -1,
"filename": "pytrafikverket-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "5588db9727b00aeebed8973f59845282",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 18856,
"upload_time": "2024-11-22T14:21:21",
"upload_time_iso_8601": "2024-11-22T14:21:21.449946Z",
"url": "https://files.pythonhosted.org/packages/45/30/538878f57307bdde4c422561fb36a4a3e67183b388c0001c6562af3d1815/pytrafikverket-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 14:21:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gjohansson-ST",
"github_project": "pytrafikverket",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytrafikverket"
}