slametps / MMM-PrayerTime

This an extension for the [MagicMirror](https://github.com/MichMich/MagicMirror). It will display prayer time (in local time).
MIT License
20 stars 10 forks source link

timetable from file - how to disable aladhan timesheet polling? #17

Closed milkywade closed 5 years ago

milkywade commented 5 years ago

Dear - first of all, many thanks for this program, God bless you.

I have more a question than an issue.

The time/method options proposed by this program did not allow me to land into an accurate timetable for where I live.

As a result, I have used the declarative self.todaySchedule "debug" options included in MMM-PrayerTime.js line 147. I wrote an external program that reads a CSV file and replaces the times mentioned in that line.

My question is the following: how can I disable the constant timesheet polling from http://api.aladhan.com/timings/ (line 129 in MMM-PrayerTime.js) without breaking the program ? I tried tinkering a little bit but every time the program breaks. I'd like for this polling to stop altogether as the computer I'm using sometimes has poor wifi and then the magicmirror is stuck with a "Charging..." message (even though I'm overwriting the timetable locally!)

many thanks!!

slametps commented 5 years ago

You may do a trial & error with 'method' value in config. If all available values not meet your need, unfortunately you should create a web service with the same output as http://api.aladhan.com/timings/ contains a more accurate prayer time for your home.

milkywade commented 5 years ago

Thank you. I actually went beyond that (as explained in my post).

Finally I figured it out today: I made the updateSchedule function in MMM-Prayertime.js have a drastic regime; mine looks like this now:

updateSchedule: function(delay) { var self = this; Log.log(self.name + ': updateSchedule'); self.todaySchedule = {"Fajr":"06:30", "Dhuhr":"13:02", "Asr":"15:18", "Maghrib":"17:44", "Isha":"18:51"}; //TEST self.nextdaySchedule = {"Fajr":"06:29", "Dhuhr":"13:02", "Asr":"15:19", "Maghrib":"17:45", "Isha":"18:52"}; //TEST self.processSchedule(); },

What I do then is to replace the "TEST" lines with the actual values coming from a separate CSV file by running automatically every morning a separate script I created.

slametps commented 5 years ago

Thank you. I actually went beyond that (as explained in my post).

Finally I figured it out today: I made the updateSchedule function in MMM-Prayertime.js have a drastic regime; mine looks like this now:

updateSchedule: function(delay) { var self = this; Log.log(self.name + ': updateSchedule'); self.todaySchedule = {"Fajr":"06:30", "Dhuhr":"13:02", "Asr":"15:18", "Maghrib":"17:44", "Isha":"18:51"}; //TEST self.nextdaySchedule = {"Fajr":"06:29", "Dhuhr":"13:02", "Asr":"15:19", "Maghrib":"17:45", "Isha":"18:52"}; //TEST self.processSchedule(); },

What I do then is to replace the "TEST" lines with the actual values coming from a separate CSV file by running automatically every morning a separate script I created.

So, your prayertime is a fixed time then? Since , the prayertime is particularly changed normally according to lunar shape/position.

milkywade commented 5 years ago

It is not fixed.

Like mentioned in this issue's title as well as in the issue description (first post at the top), I wrote an external program that every morning reads the timetable from a separate CSV file and replaces the two lines above in MMM-Prayertime.js

This approach by the way can also be used to solve the brother's issue on Diyanet times.

erkilic commented 5 years ago

Thank you milkywade. Your approach is exactly that what I had also in mind but as I'm a newby in JS programming I have no idea how to fix it. Is it possible that you send me your "external program" and give detailed advice how to incorporate that in slametps' mmm-prayertime, please ? I would be very pleased.

milkywade commented 5 years ago

Hi erkilic - see attached files. I run the python script periodically (e.g. at 5am) then restart MM for the changes to take effect. Have a look and let me know any questions.

diyanet.zip

erkilic commented 5 years ago

hi milkywade,

as I’m coming from language c, I couldn’t understand the following lines in your python script 😉

could you please explain the following lines:

for line in csv_content:

if line[6:10] != str(date.today().year):                                               // I guess, here you check if the current date is reached, but what means  6:10 ??

    continue

if stop:

    azan_tomorrow_csv = line                                                                // I think with this assignment, content of line is copied to string „azan_tomorrow_csv“

    break

line_dt = datetime.strptime(line[:10], "%d/%m/%Y")                 // datetime …… ???

if line_dt.date() == date.today():

    stop = True

    azan_today_csv = line

sorry for bothering you ;-(

thx in advance

gürkan

Von: milkywade notifications@github.com Gesendet: Mittwoch, 13. Februar 2019 22:51 An: slametps/MMM-PrayerTime MMM-PrayerTime@noreply.github.com Cc: Gürkan Erkilic mail@erkilic.de; Comment comment@noreply.github.com Betreff: Re: [slametps/MMM-PrayerTime] timetable from file - how to disable aladhan timesheet polling? (#17)

Hi erkilic - see attached files. I run the python script periodically (e.g. at 5am) then restart MM for the changes to take effect. Have a look and let me know any questions.

diyanet.zip https://github.com/slametps/MMM-PrayerTime/files/2862343/diyanet.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/slametps/MMM-PrayerTime/issues/17#issuecomment-463388756 , or mute the thread https://github.com/notifications/unsubscribe-auth/Asq2zE23KAf6LZUP3UBnO-3OWZrHLs5dks5vNIjRgaJpZM4aUZyX . https://github.com/notifications/beacon/Asq2zIlViHcELzMO4raQGSt8Z-KInuWcks5vNIjRgaJpZM4aUZyX.gif

erkilic commented 5 years ago

hi milkywade, slametps,

i’m struggling since 4 hours with installing pandas.

I have installed it with „pip install pandas“

it need some time but it has finished with „successful installed..“

pip list shows:

microdotphat (0.2.1)

mote (0.0.4)

motephat (0.0.2)

numpy (1.16.1)

oauthlib (2.0.1)

pandas (0.24.1)

pantilthat (0.0.7)

phatbeat (0.1.1)

pianohat (0.1.0)

picamera (1.13)

….

my python version is:

Python 2.7.13

unfortunately starting your

athan_parse_1.py

brings up the error:

import pandas as pd

ImportError: No module named 'pandas'

any idea why it seems not to accept my panda installation?

I hope you can help.

kind regards

gürkan

Von: milkywade notifications@github.com Gesendet: Mittwoch, 13. Februar 2019 22:51 An: slametps/MMM-PrayerTime MMM-PrayerTime@noreply.github.com Cc: Gürkan Erkilic mail@erkilic.de; Comment comment@noreply.github.com Betreff: Re: [slametps/MMM-PrayerTime] timetable from file - how to disable aladhan timesheet polling? (#17)

Hi erkilic - see attached files. I run the python script periodically (e.g. at 5am) then restart MM for the changes to take effect. Have a look and let me know any questions.

diyanet.zip https://github.com/slametps/MMM-PrayerTime/files/2862343/diyanet.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/slametps/MMM-PrayerTime/issues/17#issuecomment-463388756 , or mute the thread https://github.com/notifications/unsubscribe-auth/Asq2zE23KAf6LZUP3UBnO-3OWZrHLs5dks5vNIjRgaJpZM4aUZyX . https://github.com/notifications/beacon/Asq2zIlViHcELzMO4raQGSt8Z-KInuWcks5vNIjRgaJpZM4aUZyX.gif

milkywade commented 5 years ago

On your pandas issue, I just went through the python script and concluded that you can delete that first line as pandas is not used anywhere in that script. Just delete the first line or comment it out and the script will still work.

I must have added it at some point in time for some reason but it's not needed anymore.

milkywade commented 5 years ago

Now regarding your questions on the script, here's an overview of its workings:

  1. to reduce the effort needed in making this work on your environment, you should prepare a version of the Diyanet timesheet which follows the same format as in my CSV file (if such a thing is possible, I do not know the specifics of Diyanet times)
  2. Then you must change the CSV file path and the MMM-PrayerTime.js file path to suit your environment
  3. Once done, I recommend launching the script manually from the command line a couple of times to test it and when you're comfortable it's working as intended, you can then automate its launch through a task scheduler (e.g. crontab on linux).

More in detail and to your specific questions, this is how the script works:

Last, I generate from the python scripts a couple of strings (lines 38 & 44 in the python file I supplied) that will replace lines 179 & 180 in the MMM-PrayerTime js file I supplied with the correct times for today and tomorrow.

I open the JS file on line 53, first read it, then re-open it in write mode and finally in lines 57 to 62 of the python file, I rewrite lines 179 & 180 of the JS file with the strings I generated in lines 38 & 44 of the python file.

I don't know if it's the best way to do it or the prettiest and it does need additional failsafes but it works for me. I guess best would be to build it in java script and integrate it in slamet's program directly but my JS is not as good as my python these days and I did not had the chance to spend a couple of hours to understand how MM modules work.

Hope this helped !

erkilic commented 5 years ago

Thank you very much milkywade, now I understood how it is working. I have worked on it last weekend . Together wirh the Diyanet times I found on their webpage, I filled up your csv file and it has worked very well. Again thanks a lot for your help and your tricky program!

milkywade commented 5 years ago

Sure, glad it worked :-)