#!/usr/bin/python3
## Compute Zao Keng to A-frame azimuths
## https://www.jidanni.org/astro/reflections/a-frame/programs/r
##
## Here we use https://github.com/brandon-rhodes/pyephem
## via the Debian python3-ephem package.
##
## Warning: I (jidanni) am a python nincompoop, so don't use these as code examples!
##
## Copyright       : https://www.gnu.org/licenses/gpl.html
## Author          : https://www.jidanni.org/
## Created On      : Sun May  9 19:49:22 2021
## Last Modified By: Dan Jacobson
## Last Modified On: Mon May 31 21:33:14 2021
## Update Count    : 150
# /usr/lib/python3/dist-packages/ephem/doc/quick.rst

import ephem, math, os

tf = True
p = ephem.Observer()
p.lon, p.lat = os.environ["lon"], os.environ["lat"]
# p.elevation = float(os.environ["ASL"])  # Doesn't do much.
# p.elevation = 50  # Doesn't do much.
# p.date = str(ephem.now().tuple()[0])  # Beginning of current year (UTC).
f = ephem.Sun(p)


def pr(k):
    v = ephem.Sun(k)
    print(
        "%.19s %.1f %.1f"
        % (ephem.localtime(k.date), v.az * 180 / math.pi, v.alt * 180 / math.pi)
    )


def white(p):
    odate = ephem.Date("2021/01/01 05:00")
    dmax = 365
    d = 0
    while d <= dmax:
        p.date = odate + d
        date3 = p.date + 3 * ephem.hour
        while p.date <= date3:
            pr(p)
            p.date += ephem.minute * 10
        print()
        d += 3


# At certain times of the day, the roof will even become white!
# If the sun is not hitting the roof at all, then it is dark. Once it
# begins hitting the roof, it is red.


# One way the sun hits roof is the sun's azimuth is beyond the roof's:
# (If the roof was north south oriented, the sun would hit starting at noon. Else lags.)
# Hey, what about the morning?
eval(os.environ["func"])  # My poor python knowledge

# All throughout the above of course we are talking about sunny days,
# not cloudy days.
