Coder Social home page Coder Social logo

pygti's Introduction

HVV Geofox Python Library

Code style: black Hamburg Open Issues Release GTI version: 38 Azure Pipelines status


About

This library is a python wrapper for accessing the geofox api. This api is used to get information about the public transport in Hamburg, Germany.

How to get the api credentials

You have to apply for credentials via the HVV website. You can see their official guide here (the page is only available in German).

They will send you a contract you will have to sign and send back. After about a week, you will receive your api credentials.

Documentation

This library uses the same data types and parameters as specified in the GTI documentation. It features client side validation of the parameters.

Installation

Install the package from pypi.

pip install pygti

Usage

See the examples on how to use the library at examples.py, and see the GTI documentation for in-depth explanation of parameters.

There is also a Glitch example available. Try it out and if you want to see how it's done, just remix the app.

A minimal working example is shown below:

from pygti.gti import GTI, Auth
import asyncio
import aiohttp

GTI_USER = "" # your api username
GTI_PASS = "" # your api password


async def main():
    async with aiohttp.ClientSession() as session:
        auth = Auth(session, GTI_USER, GTI_PASS)

        gti = GTI(auth)

        ir = await gti.init()

        # see the examples.py file for more functionality and use of the payloads

asyncio.run(main())

โ— If using Python 3.8: Version 3.6.2 of aiohttp uses a different EventLoopPolicy so running this MWE will currently result in an error displayed in the console! It should not affect the functionality. This should be fixed with a newer version of aiohttp. For a workaround look into the examples.py file. For more information see this Issue.

Progress

  • 1. init
  • 2. checkName
  • 3. getRoute
  • 4. departureList
  • 5. getTariff
  • 6. departureCourse
  • 7. listStations
  • 8. listLines
  • 9. getAnnouncements
  • 10. getIndividualRoute
  • 11a. getVehicleMap
  • 11b. getTrackCoordinates
  • 12. checkPostalCode
  • 13. getStationInformation
  • 14. tariffZoneNeighbours
  • 15. tariffMetaData
  • 16. singleTicketOptimizer
  • 17. ticketList

Developing

Some files in this project are generated based on the WADL and XSD schema files from GTI. To generate them, install the dev dependencies and run the script:

pip install -r requirements_dev.txt
python script/generate.py

Contributions are welcome!

If you want to contribute to this, please read the Contribution guidelines

pygti's People

Contributors

chronob avatar dependabot-preview[bot] avatar dotlambda avatar pvizeli avatar vigonotion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pygti's Issues

getTrackCoordinates returns error

The example of the getTrackCoordinates() requests returns an error.

Steps to reproduce:

  • clone repo from git
  • pip install -r requirements
  • add .env file with api credentials
  • python example.py

Error

Example 12: getTrackCoordinates()
Traceback (most recent call last):
File ".\examples.py", line 218, in
asyncio.run(main())
File "c:\python38\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "c:\python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File ".\examples.py", line 192, in main
tc = await gti.getTrackCoordinates(payload)
File "C:\Users\finno\Documents\Github\pygti\pygti\gti.py", line 58, in getTrackCoordinates
response = await self.auth.request(
File "C:\Users\finno\Documents\Github\pygti\pygti\auth.py", line 75, in request
raise GTIError(return_code, error_text, error_dev_info)
pygti.exceptions.GTIError: ('ERROR_TEXT', 'Bei der Verarbeitung der Anfrage ist ein technisches Problem aufgetreten.', 'Internal server error')


I just looked into the documentation and saw that they updated the version of the API in March, but updating the version to 38 in the payload did not help. i also used the payload from the doc (2.11.6 p. 71), just without the dots at the end. That didn't work either.
I don't really understand the usage of this function so i don't know where to look next...

update to new API version

API version 38 was released in march.

  • Update examples to use API 38 instead of 37.

Question:

  • In the auth.py file in l. 40 you update the version in the payload. I couldn't find any documentation in the Voluptuous Readme about updating a schema. Does it add the parameter "version" if it is not there or does it update the parameter to be 37 all the time?
    I think it would be good to then have an optional version number in the requests and if the user adds one to specify the version it should be prioritized over the standard. Also a way to set the standard version via a higher level function could be a good thing.

Update to new api version

I know from a reliable source ( ;-) ) that older GTI API versions will soon be ignored or switched off.
I would therefore be happy if the current GTI version is used.

aiohttp throws "RuntimeError: Event loop is closed"

When using the repo with Python3.8 the aiohttp library throws a "RuntimeError: Event loop is closed" when operation has ended.
It does not the affect the correct functionality of the program. It just clusters the output of it.

The error and a possible workaround is described here:
iojw/socialscan#13

We should have an eye on the next aiohttp lib update and update our requirements accordingly

Feature request: Home Assistant integration.

Hello,

I just discovered your project and thought it would be great if there would be an integration for HA.

Is it maybe possible that you write an integration for HA?
I think I can't help yout with it, because I have no programming experience. Maybe I can assistant during tests or something else.

Thank you in advance.

Greetings from Hamburg.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.