pinsdorf / MMM-WeeklySchedule

Module for MagicMirror which shows a weekly timetable. Might be helpful for students/teachers/parents to show class schedules, weekly gym courses, sports training sessions, and general weekly recurring events.
MIT License
65 stars 26 forks source link

weekly change of schedule #6

Closed maxfelc closed 5 years ago

maxfelc commented 5 years ago

Hi! first of all: nice work! love that module. I'm a student in 11th grade and today "back to school" started and I got a new timetable. But this years timetable is now structured in A-weeks and B-weeks. The weeks change, depending on the calendar weeks number :

So I technically have two independently working timetables.

QUESTION: how can I implement those two timetables in the module with a weekly change?

Thanks for reading this!

Greetings from Germany, Max

pinsdorf commented 5 years ago

Hi @maxfelc, thanks for your kind post. Much appreciated! Your use case is indeed very interesting. The current module code cannot solve it. I would have to extend it to define even/odd week's schedules. This will take a little time ...

I have a poor man's solution for you that would work right away. Please use cron job that runs once a week, changes the config.js, and restarts the mirror. Use crontab -e to modify cron configuration. Configuration should look like this (not tested):

* 22 * * 0 ~/MagicMirror/config/update-schedule

It executes a script update-schedule every sunday at 10pm. The script looks like this:

#!/bin/bash
week=$(date +%U)
if [ $(($week % 2)) == 0 ]; then 
    cp -f ~/MagicMirror/config/config.week-A.js ~/MagicMirror/config/config.js
else 
    cp -f ~/MagicMirror/config/config.week-B.js ~/MagicMirror/config/config.js
fi
pm2 restart mm

I took some hints from this discussion on serverfault.com. The script simply reads the week number, modulo divides it by 2, and compares the remainder against 0 or 1 respectively. Depending on the result it copies config.week-A.js or config.week-B.js to config.js. The forcing flag -f overwrites the existing config.js.

Again, above is not tested, but may show you the path. I'd love to learn about your solution.

maxfelc commented 5 years ago

Thanks for the quick help! I will definitely try it and inform you about my solution!

pinsdorf commented 5 years ago

Hi @maxfelc, I will close this pull request and move our conversation over to issue #9. This helps me better keeping track of ideas & bug reports versus code changes. At the same time I don't want to loose your good idea.

Please reply to the conversation in issue #9, once you've had the time to try the poor man's solution above. Thanks!