0
Answered

Logic to iterate through output and grab the "correct" Shabbat

Leon Adato 3 years ago updated by Michael J. Radwin 3 years ago 2

NOTE: The issue below is a programming question. I'm relatively new to "real" coding (versus utility scripts with very narrow scopes), so my belief is that this is a simple case of how to build the correct looping and logic structures. It's not an issue with the API itself or my use of it. I think.
************************
I'm building an automatically-generated list of Shabbat dates and calculating times for mincha, candles, etc based on my shul's particular shitot. I want to grab every Saturday, but I only want to grab each Saturday ONCE.


My problem is that if I set the Major holiday switch (maj) to off, I'm missing some Shabbats.

(example, 9/23 because that's shabbat chol hamoed Sukkot, not a normal Shabbat.)


BUT if I include maj=on, I get some double saturdays

(example: 12/04, which is a 'regular' Shabbat but also noted as the 7th night of Chanukah)


So I need to figure out how to programatically grab or filter the "correct" one.

Here's a sample of the API string I'm generating:

https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=off&nx=off&mf=off&ss=off&s=on&c=off&i=off&leyning=off&geo=pos&latitude=41.4902062&longitude=-81.517477&tzid=America/New_York&start=2021-09-07&end=2022-09-26


To see the current state of the code, check here:
https://clevelandsephardiminyan.com/wp-content/zmanim/fullyear_0-3.php

And the code (such as it is) can be found here:
https://github.com/adatole/sephardic_zmanim_fullyear

Answered

Glad you got the problem solved!

I worked through my own issue. In the end rather than print each line, I pushed each line into an associative array. Before adding a line, I check to see if it's already there AND that the tag is "parashat". If it is, I leave it. If it's not, I write (or over-write) the line. You can find the code on github:
https://github.com/adatole/sephardic_zmanim_fullyear

and you can see it running here:
https://clevelandsephardiminyan.com/wp-content/zmanim/fullyear.php