Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
milkywade opened this issue Jan 26, 2019 · 12 comments
Closed

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

milkywade opened this issue Jan 26, 2019 · 12 comments

Comments

@milkywade
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

milkywade commented Feb 12, 2019

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
Copy link

erkilic commented Feb 13, 2019

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
Copy link
Author

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
Copy link

erkilic commented Feb 15, 2019 via email

@erkilic
Copy link

erkilic commented Feb 15, 2019 via email

@milkywade
Copy link
Author

milkywade commented Feb 17, 2019

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
Copy link
Author

milkywade commented Feb 17, 2019

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:

  • Line 17 & 18: it opens & reads the CSV file with your timesheet into the csv_content variable
  • Line 20 it processes your file's contents, line by line. It first checks in line 21 that the year in the line (positions 6 to 10) is today's year (failsafe in case the file would contain date from other years). Then in lines 27 & 28 it checks that the date in the line is the same as today. If so, then it reads the next line then exits the loop. This way, after the loop's execution, you have the CSV line with today's prayer times in azan_today_csv and tomorrow's in azan_tomorrow_csv.

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
Copy link

erkilic commented Feb 18, 2019

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
Copy link
Author

Sure, glad it worked :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants