• AI Written Bash Script

    From DrStevenStrange@3:770/3 to All on Thursday, December 12, 2024 12:43:14
    Ok - don't laugh

    My coding skills are pitiful so I asked my resident Ai to write a bash
    script to call a webcam script (I did write this one) only between
    sunrise and sunset. it produced this and it works! My question is - how
    can I amend the script so it starts 30 minutes BEFORE sunrise and stops
    30 Minutes after?

    #!/bin/bash

    # Set your latitude and longitude
    LATITUDE="mine"
    LONGITUDE="mine"

    # Fetch sunrise and sunset times in UTC
    SUN_TIMES=$(curl -s "https://api.sunrise-sunset.org/json?lat=$LATITUDE&lng=$LONGITUDE&formatted=0") SUNRISE=$(echo $SUN_TIMES | jq -r '.results.sunrise')
    SUNSET=$(echo $SUN_TIMES | jq -r '.results.sunset')

    # Convert sunrise and sunset times to seconds since epoch
    SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
    SUNSET_EPOCH=$(date -d "$SUNSET" +%s)
    CURRENT_EPOCH=$(date +%s)

    # Check if the current time is between sunrise and sunset
    if [ $CURRENT_EPOCH -ge $SUNRISE_EPOCH ] && [ $CURRENT_EPOCH -le
    $SUNSET_EPOCH ]; then
    echo "It's between sunrise and sunset. Running the other script..."
    # Call the other script
    ./webcam.sh # Replace with the path to your script
    else
    echo "It's not between sunrise and sunset."
    fi

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From =?UTF-8?Q?Josef_M=C3=B6llers?=@3:770/3 to DrStevenStrange on Thursday, December 12, 2024 14:36:55
    On 12.12.24 13:43, DrStevenStrange wrote:
    Ok - don't laugh

    My coding skills are pitiful so I asked my resident Ai to write a bash
    script to call a webcam script (I did write this one) only between
    sunrise and sunset. it produced this and it works! My question is - how
    can I amend the script so it starts 30 minutes BEFORE sunrise and stops
    30  Minutes after?
    [...]
    # Convert sunrise and sunset times to seconds since epoch SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
    SUNSET_EPOCH=$(date -d "$SUNSET" +%s)
    CURRENT_EPOCH=$(date +%s)

    Since you already have the date/times in seconds since the epoch, just add/subtract 30 minutes worth of seconds for AFTER and BEFORE!

    Josef

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From =?UTF-8?Q?Josef_M=C3=B6llers?=@3:770/3 to DrStevenStrange on Thursday, December 12, 2024 14:35:32
    On 12.12.24 13:43, DrStevenStrange wrote:
    Ok - don't laugh

    My coding skills are pitiful so I asked my resident Ai to write a bash
    script to call a webcam script (I did write this one) only between
    sunrise and sunset. it produced this and it works! My question is - how
    can I amend the script so it starts 30 minutes BEFORE sunrise and stops
    30  Minutes after?
    [...]

    SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
    SUNSET_EPOCH=$(date -d "$SUNSET" +%s)
    CURRENT_EPOCH=$(date +%s)

    Since you already have the date/time in seconds since the epoch, just
    subtract 30 seconds for BEFORE and add 30 seconds for AFTER

    Josef

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From mm0fmf@3:770/3 to DrStevenStrange on Thursday, December 12, 2024 21:20:08
    On 12/12/2024 12:43, DrStevenStrange wrote:
    how can I amend the script so it starts 30 minutes BEFORE sunrise and
    stops 30  Minutes after?

    Why not just ask the AI goonbot to do that?

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Lawrence D'Oliveiro@3:770/3 to DrStevenStrange on Thursday, December 12, 2024 21:14:38
    On Thu, 12 Dec 2024 12:43:14 +0000, DrStevenStrange wrote:

    ... how can I amend the script so it starts 30 minutes BEFORE sunrise
    and stops 30 Minutes after?
    ...
    SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
    SUNSET_EPOCH=$(date -d "$SUNSET" +%s)

    How about

    SUNRISE_EPOCH=$(($(date -d "$SUNRISE" +%s) - 1800))
    SUNSET_EPOCH=$(($(date -d "$SUNSET" +%s) + 1800))

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From DrStevenStrange@3:770/3 to Lawrence D'Oliveiro on Friday, December 13, 2024 06:57:08
    Lawrence D'Oliveiro wrote:
    On Thu, 12 Dec 2024 12:43:14 +0000, DrStevenStrange wrote:

    ... how can I amend the script so it starts 30 minutes BEFORE sunrise
    and stops 30 Minutes after?
    ...
    SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
    SUNSET_EPOCH=$(date -d "$SUNSET" +%s)

    How about

    SUNRISE_EPOCH=$(($(date -d "$SUNRISE" +%s) - 1800))
    SUNSET_EPOCH=$(($(date -d "$SUNSET" +%s) + 1800))


    Many thanks

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From f6k@3:770/3 to none@invalid.com on Tuesday, December 17, 2024 01:08:11
    On 2024-12-12, mm0fmf <none@invalid.com> wrote:
    On 12/12/2024 12:43, DrStevenStrange wrote:
    how can I amend the script so it starts 30 minutes BEFORE sunrise and
    stops 30  Minutes after?

    Why not just ask the AI goonbot to do that?

    Same, same!

    -f

    --
    ~{,_,"> huld.re <",_,}~

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)