Opening hours for stores/places thru Google API



  • Hi!

    I would like to be able to enter a list of my favorite stores/places and get a simple list of current opening hours.

    I.e., if the list contains:
    McDonald “My localtion”, Library “My location”, Restaurant_name.

    An API call to google:
    https://developers.google.com/places/web-service/details#PlaceDetailsResults
    … and the result from:
    opening_hours

    The module would then present a list with the following results:

    Name - Status
    McDonald - “Open Now”
    Library - “Closes in 30 min”
    Restaurant_name - “Closed”

    Wouldn´t that be nice?! 😃

    Example of data pulled from a classic google search.

    0_1549223649197_MMMOpeninghours.png

    BR
    Tilly



  • @htilly Here you go! MMM-OpeningHours 🙂
    What do you think?



  • Awesome!!! 🚀

    Installing today to try it out.
    Look really nice!

    🙏



  • @Menturan said in Opening hours for stores/places thru Google API:

    What do you think?

    Hi,

    Wanted to give it a try.
    By coincidence went to a place that was closed and this module could have saved me the trip.

    My first thought was: really ?

    1. yarn install
    

    But I know it is under development and you do this voluntary, so I cannot really complain (never submitted a single module myself).
    I do like Mich’s General Advise.
    https://github.com/MichMich/MagicMirror/tree/master/modules

    Most if not all modules use git clone and an occasional npm install

    $ git clone https://github.com/Menturan/MMM-OpeningHours.git
    $ npm install
    

    I was so stubborn to install it this way, as I do not want to find out how yarn works.
    I got it running to the point where on the MM I see:
    Loading opening hours ...
    The pm2 logs does not give an error or warning or so.
    I see it converted my place id to a real address, so it means that my Google API key is okay.

    I will try it again with the debug parameter on, but can you tell me what I should see when the opening times are fetched (in pm2 logs) ?
    And perhaps really need yarn ?
    But then an explanation is needed; a plain yarn install won’t do.

    So, thanks for the module, but would be nice to get it working.



  • Hi,

    Regarding yarn or npm is just a matter of package managers. As far as I understand you could probably happily do what you described using npm if that feels better.

    now, for the data. I installed it and had the same problem as you describe. First of, make sure that you do have a Google API registered and working. Assuming that you have this, my installation started to work after a reboot of the Raspberry Pi.
    I guess that it will not initiate a new API call after changing the config for MagicMirror.

    And to be clear, I have not coded this. I’m the one that requested the feature, and I simply love the delivery. Exactly what I wanted!!

    BR
    Tilly



  • Rebooted.
    No change.

    I do get this error:

    0|mm  | [5:13:03 PM] - MMM-OpeningHours : Starting helper:  MMM-OpeningHours
    0|mm  | Sockets connected & modules started ...
    0|mm  | Launching application.
    0|mm  | (node:2342) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'refs' of undefined
    0|mm  | (node:2342) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    

    I suppose the API key is right, as it finds the (street)name.
    And it increases the usage counter for Google Places for my account.

    But no opening times.
    On Google Maps opening times are visible for this ID.

    0|mm  |   json:
    0|mm  |    { html_attributions: [],
    0|mm  |      result: { name: 'Laufamholzstraße 76' },
    0|mm  |      status: 'OK' },
    0|mm  |   requestUrl: 'https://maps.googleapis.com/maps/api/place/details/json?fields=name%2Copening_hours&language=en&placeid=ChIJ9SpsbxZYn0cRhBEv4PE_Tvs&key=',
    0|mm  |   query:
    0|mm  |    { fields: 'name,opening_hours',
    0|mm  |      language: 'en',
    0|mm  |      placeid: 'ChIJ9SpsbxZYn0cRhBEv4PE_Tvs',
    0|mm  |      key: '' } }
    

    And I do not see a mapping between place id, street name and the name of the place.



  • I tried it and it seems to be something strange with the PlaceID.
    Try this ID instead:
    ChIJl7ycbxZYn0cRqZwkVTJ3Rzw

    Should be the same place.

    /Tilly



  • @htilly said in Opening hours for stores/places thru Google API:

    Try this ID instead:

    Thanks for spending time on it.

    Strange, but it works.
    The Place finder really says “ChIJ9SpsbxZYn0cRhBEv4PE_Tvs”, how did you find “ChIJl7ycbxZYn0cRqZwkVTJ3Rzw” ??

    0_1553893557312_Screenshot 2019-03-29 at 22.04.51.png



  • Just FYI
    Simple test if both API key and place ID are okay using curl.

    This returns both name & opening_hours (as it should be):

    $ curl "https://maps.googleapis.com/maps/api/place/details/json?fields=name,opening_hours&language=en&placeid=ChIJl7ycbxZYn0cRqZwkVTJ3Rzw&key="API_KEY"
    

    In my case, it returned only the name:

    $ curl "https://maps.googleapis.com/maps/api/place/details/json?fields=name,opening_hours&language=en&placeid=ChIJ9SpsbxZYn0cRhBEv4PE_Tvs&key="API_KEY"
    

    Still confused why the place ID from Place Finder seems a bit off.



  • Hi Guys,
    (This is my first post 😛 but I have problems with this amazing module so I hope you could help)
    I have basically the same problem as evroom. My API is working (I do get the requested information at least with the link: "https://maps.googleapis.com/maps/api/place/details/json?fields=name,opening_hours&language=en&placeid=....
    I installed it with npm install and the module is just saying “Loading Opening Hours”.
    I just set debug: "true",but i don’t know where to find the debug file ^^ (I’m pretty new to all of this)
    Any idea for a fix? And this module is amazing (when it works) We always struggle to know if a certain shop is still open xD
    Best, Ben

    PROBLEM SOLVED:
    At least for me, I just had to wait until after midnight and the data got fetched again and is showing now everything properly. So for everyone with the same problem, maybe just wait until the next day 🙂