leftshift / python_mvg_api

Yet another library for fetching MVG departures.
https://pypi.org/project/mvg-api/
MIT License
65 stars 18 forks source link

Document Micropython compatiblity #23

Open peterfroehlich opened 4 years ago

peterfroehlich commented 4 years ago

Hey guys!

This awesome library can be made to work with micropython easily by using the micropython port of datetime and using the micropython versions of time and requests:

@@ -1,8 +1,8 @@
 # coding=utf-8

-import requests
+import urequests as requests
 import datetime
-from time import mktime
+import utime as time

Thats it, everything I tried worked.

What do you think, just a section in the README, an already patched file in a subfolder or a edited fork in a new repo?

XOX

leftshift commented 4 years ago

Thanks for the praise! Ohh, that's actually pretty cool, thanks for trying that out :D It appears we could also check sys.implementation.name to see whether we're running on micropython and import the right modules depending on that. I'm not 100% sure what I think about that but it would have the advantage of not having to maintain multiple different variants. Unfortunately, I don't have a micropython board handy right now, but I'll try around in the unix micropython variant.

s6adhimm commented 1 year ago

Hey there! I found this awesome package a couple of days ago and wanted to make it run on my ESP8266 as well. But unfortunately any urequests.get command to mvg raises a OS Error -40 . @peterfroehlich if your still around do you have any idea where this could be coming from and how to fix it?

Stephaela commented 1 year ago

Hey everyone! I'm also currently working on that topic. @s6adhimm I am not sure if I can help you, but I'll try. If you still have this problem, could you please try the following minimal example code:

import urequests response = urequests.get(url='https://www.mvg.de/api/fahrinfo/departure/de:09184:490?footway=0') print(response.json())

I don't have the same microcontroller like you, I have a Raspberry Pi Pico W, and on this board the example code above works, it is supposed to display the departures from Garching. Could you please tell me if this code works for you? :)

For me, not all parts of the code in this repository worked for my microcontroller, but I was able to adapt it in order to get all the information I wanted. :)