generated from me/template-mit
Compare commits
9
Commits
main
..
ac88d08213
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac88d08213 | ||
|
|
ccf6e69054 | ||
|
|
50ae6a0f66 | ||
|
|
152758e03b | ||
|
|
1bd33a768f | ||
|
|
5601cd0f56 | ||
|
|
cbca8ac5d2 | ||
|
|
4bed4e5aff | ||
|
|
258d5e9e0a |
No files matched your search
+65
-29
@@ -5,10 +5,12 @@
|
|||||||
## Variables ##
|
## Variables ##
|
||||||
|
|
||||||
DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||||
|
PROJ="$(cd "$DIR"/.. &>/dev/null && pwd)"
|
||||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||||
LOCAL=~/bin
|
LOCAL=~/bin
|
||||||
GLOBAL=/usr/local/bin
|
GLOBAL="/usr/local"
|
||||||
GLOBAL_SRC=/usr/local/src
|
GLOBAL_BIN="$GLOBAL/bin"
|
||||||
|
GLOBAL_SRC="$GLOBAL/src"
|
||||||
|
|
||||||
name_local="prototype.js"
|
name_local="prototype.js"
|
||||||
name_short="nomad"
|
name_short="nomad"
|
||||||
@@ -19,88 +21,122 @@ name_abs="weather-list"
|
|||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
cat <<- EOF
|
cat <<- EOF
|
||||||
$PROG [-h] [-g] [a|l|s] [-r]
|
$PROG [-h] [-g] [a: b|l|s] [-r]
|
||||||
|
|
||||||
Install $name_local to the system. Can be local, global, or removed.
|
Install $name_local to the system. Can be local, global, or removed.
|
||||||
|
|
||||||
Parameters)
|
Parameters)
|
||||||
h) Display this message.
|
h) Display this message.
|
||||||
g) Install globally ($GLOBAL), otherwise local ($LOCAL).
|
g) Install globally ($GLOBAL), otherwise local ($LOCAL).
|
||||||
a) Abstract name, unrelated to being nomadic. ($name_abs)
|
a) All names / pseudonyms, rather than choosing from below.
|
||||||
l) Long name, the full name of the project. ($name_long)
|
b) Basic name, unrelated to being nomadic. ($name_abs)
|
||||||
|
l) Long name, the full name of the project. ($name_long) [Default]
|
||||||
s) Short name, the full name of the project. ($name_short)
|
s) Short name, the full name of the project. ($name_short)
|
||||||
r) Remove / uninstall the project according to the above flags.
|
r) Remove / uninstall the project according to the above flags.
|
||||||
|
|
||||||
Examples)
|
Examples)
|
||||||
- Install to the local user with the abstract name.
|
- Install to the local user with the default name.
|
||||||
$PROG
|
$PROG
|
||||||
- Install to all users with all names.
|
- Install to all users with all names.
|
||||||
$PROG -alsg
|
$PROG -ga
|
||||||
- Remove all instances.
|
- Remove all instances.
|
||||||
$PROG -alsr && $PROG -alsrg
|
$PROG -ra && $PROG -gra
|
||||||
|
|
||||||
Happy weather watching! :)
|
Happy weather watching! :)
|
||||||
|
|
||||||
~ Hyperling
|
~ Hyperling
|
||||||
|
|
||||||
|
https://git.hyperling.com/me/nomadic-weather
|
||||||
EOF
|
EOF
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Validations ##
|
||||||
|
|
||||||
|
count=0
|
||||||
|
while [[ ! -d "$DIR/node_modules" ]]; do
|
||||||
|
if (( count > 0 )); then
|
||||||
|
echo "Failed to download libraries, please intervene."
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
if [[ -z "`which npm`" ]]; then
|
||||||
|
echo "Libraries are missing, please run 'npm install' first."
|
||||||
|
exit 2
|
||||||
|
else
|
||||||
|
echo "Downloading libraries with 'npm install'."
|
||||||
|
cd $DIR && npm install
|
||||||
|
fi
|
||||||
|
count=$(( count++ ))
|
||||||
|
done
|
||||||
|
|
||||||
## Parameters ##
|
## Parameters ##
|
||||||
|
|
||||||
while getopts ":gslarh" arg; do
|
while getopts ":gslabrh" arg; do
|
||||||
case $arg in
|
case $arg in
|
||||||
g) global="Y" ;;
|
g) global="Y" ;;
|
||||||
s) short="Y" ;;
|
s) short="Y" ;;
|
||||||
l) long="Y" ;;
|
l) long="Y" ;;
|
||||||
a) abstract="Y" ;;
|
b) abstract="Y" ;;
|
||||||
|
a) all="Y" ;;
|
||||||
r) remove="Y" ;;
|
r) remove="Y" ;;
|
||||||
h) usage ;;
|
h) usage ;;
|
||||||
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
## Processing ##
|
|
||||||
|
|
||||||
name=""
|
name=""
|
||||||
if [[ "$short" == "Y" ]]; then
|
if [[ "$all" == "Y" || "$abstract" == "Y" ]]; then
|
||||||
name="$name $name_short"
|
|
||||||
fi
|
|
||||||
if [[ "$long" == "Y" ]]; then
|
|
||||||
name="$name $name_long"
|
|
||||||
fi
|
|
||||||
if [[ "$abstract" == "Y" || ( -z "$short" && -z "$long" ) ]]; then
|
|
||||||
name="$name $name_abs"
|
name="$name $name_abs"
|
||||||
fi
|
fi
|
||||||
|
if [[ "$all" == "Y" || "$short" == "Y" ]]; then
|
||||||
|
name="$name $name_short"
|
||||||
|
fi
|
||||||
|
if [[ "$all" == "Y" || "$long" == "Y" || -z "$name" ]]; then
|
||||||
|
name="$name $name_long"
|
||||||
|
fi
|
||||||
|
|
||||||
|
termux_check="/sdcard"
|
||||||
|
if [[ "$global" == "Y" && -e "$termux_check" ]]; then
|
||||||
|
echo "Detected $termux_check, assuming we are on Termux, global flag disabled."
|
||||||
|
global="N"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Processing ##
|
||||||
|
|
||||||
cmd=""
|
cmd=""
|
||||||
dir="$LOCAL"
|
dir="$LOCAL"
|
||||||
src="$DIR"
|
src="$PROJ"
|
||||||
if [[ "$global" == "Y" ]]; then
|
if [[ "$global" == "Y" ]]; then
|
||||||
dir="$GLOBAL"
|
|
||||||
cmd="sudo"
|
cmd="sudo"
|
||||||
|
dir="$GLOBAL_BIN"
|
||||||
|
src="$GLOBAL_SRC/`basename "$PROJ"`"
|
||||||
echo "Requesting sudo privileges... "
|
echo "Requesting sudo privileges... "
|
||||||
sudo echo "Success!"
|
sudo echo "Success!"
|
||||||
mkdir -pv /usr/local/src
|
|
||||||
sudo cp -Rv "$DIR" $GLOBAL_SRC/
|
|
||||||
src="$GLOBAL_SRC/`basename "$DIR"`"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$remove" ]]; then
|
if [[ -z "$remove" ]]; then
|
||||||
cmd="$cmd ln -svf $src/$name_local"
|
cmd="$cmd ln -svf $src/cli/$name_local"
|
||||||
else
|
else
|
||||||
cmd="$cmd rm -v"
|
cmd="$cmd rm -v"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Main ##
|
## Main ##
|
||||||
|
|
||||||
# Untested
|
# Global Source Code: Install / Removal
|
||||||
#if [[ "$global" == "Y" && "$remove" == "Y" ]]; then
|
if [[ "$global" == "Y" ]]; then
|
||||||
# sudo rm -rfv "$src"
|
if [[ "$remove" == "Y" ]]; then
|
||||||
#fi
|
sudo rm -rfv "$src"
|
||||||
|
else
|
||||||
|
mkdir -pv "$GLOBAL_SRC"
|
||||||
|
sudo cp -Rv "$PROJ" "$GLOBAL_SRC"/
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Program: Install / Removal
|
||||||
for prog in $name; do
|
for prog in $name; do
|
||||||
|
if [[ ! -d "$dir" ]]; then
|
||||||
mkdir -pv "$dir"
|
mkdir -pv "$dir"
|
||||||
|
fi
|
||||||
$cmd "$dir/$prog"
|
$cmd "$dir/$prog"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Vendored
+94
-65
@@ -23,63 +23,48 @@
|
|||||||
* - added args, basically took over the program without any incremental commits
|
* - added args, basically took over the program without any incremental commits
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
/* TODO
|
||||||
|
* - Add way to manage a DB such as ~/.confg/nomadic-weather/locations.json
|
||||||
|
* - -c argument for creating locations
|
||||||
|
* - Should act like "read" to intake data for Season, Nickname, Lat, Long, and Elevation.
|
||||||
|
* - -d argument for deleting locations
|
||||||
|
* - Displays the list and asks which index# to delete.
|
||||||
|
* - -m argument for modifying locations
|
||||||
|
* - Displays a list and asks which index to open, then goes through create-like process.
|
||||||
|
* - Tie locations to seasons, as noted for the GUI in the Design, and sort on that rather than elevation.
|
||||||
|
* */
|
||||||
|
|
||||||
|
/* * * Libraries * * */
|
||||||
|
|
||||||
const yargs = require('yargs/yargs');
|
const yargs = require('yargs/yargs');
|
||||||
const { hideBin } = require('yargs/helpers');
|
const { hideBin } = require('yargs/helpers');
|
||||||
|
|
||||||
const version = '0.0.1';
|
/* * * Variables * * */
|
||||||
|
|
||||||
|
const version = '0.1.2';
|
||||||
|
|
||||||
const days_fore_max = 16;
|
const days_fore_max = 16;
|
||||||
const days_fore_default = 12;
|
const days_fore_default = 7;
|
||||||
const days_past_default = 2;
|
const days_past_default = 7;
|
||||||
|
|
||||||
const ft_to_m = 0.3048;
|
const ft_to_m = 0.3048;
|
||||||
|
|
||||||
const argv = yargs(hideBin(process.argv))
|
const RED = "\x1b[31m";
|
||||||
.option('days_fore', {
|
const GRN = "\x1b[32m";
|
||||||
alias: 'f',
|
const YLW = "\x1b[33m";
|
||||||
describe: 'Set forecast days, such as "-f 10". Maximum of 16.',
|
const BLU = "\x1b[34m";
|
||||||
type: 'number',
|
const MGN = "\x1b[35m";
|
||||||
requiresArg: true,
|
const CYN = "\x1b[36m";
|
||||||
})
|
const WHT = "\x1b[37m";
|
||||||
.option('days_past', {
|
const RESET = "\x1b[0m";
|
||||||
alias: 'p',
|
|
||||||
describe: 'Set past days, such as "-p 3"',
|
|
||||||
type: 'number',
|
|
||||||
requiresArg: true,
|
|
||||||
})
|
|
||||||
.option('calc_elevation', {
|
|
||||||
alias: 'e',
|
|
||||||
describe: 'Set to calculate elevation at lat/long.',
|
|
||||||
type: 'boolean',
|
|
||||||
})
|
|
||||||
.check((argv) => {
|
|
||||||
if (argv.f !== undefined && (isNaN(argv.f) || argv.f < 0)) {
|
|
||||||
throw new Error('Forecast days must be a non-negative number');
|
|
||||||
}
|
|
||||||
if (argv.p !== undefined && (isNaN(argv.p) || argv.p < 0)) {
|
|
||||||
throw new Error('Past days must be a non-negative number');
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
//.demandOption(['timeout', 'debug']) // Optional: require these arguments
|
|
||||||
.strict()
|
|
||||||
.help()
|
|
||||||
.version(version)
|
|
||||||
.argv
|
|
||||||
;
|
|
||||||
|
|
||||||
function max (value, upper) {
|
const pref_high_upper = 75;
|
||||||
return (value > upper) ? upper : value;
|
const pref_high_lower = 60;
|
||||||
}
|
const pref_low_upper = 55;
|
||||||
const days_fore = max(argv.hasOwnProperty("days_fore") ? argv.days_fore : days_fore_default, days_fore_max);
|
const pref_low_lower = 40;
|
||||||
const days_past = argv.hasOwnProperty("days_past") ? argv.days_past : days_past_default;
|
|
||||||
const calc_elevation = argv.calc_elevation ? true : false;
|
|
||||||
|
|
||||||
const days = days_fore + days_past;
|
const tolerance_light = 10;
|
||||||
|
const tolerance_heavy = 20;
|
||||||
console.log(`Averaging for ${days} days: ${days_fore} forecasted, ${days_past} past.`);
|
|
||||||
if (calc_elevation) console.log("Calculating elevation rather than using provided values.");
|
|
||||||
else console.log("Using user-provided elevations when they exist.");
|
|
||||||
|
|
||||||
const locations = [
|
const locations = [
|
||||||
//{ name: "Flagstaff, AZ", lat: 35.1983, lon: -111.6513, elevation: 6903 },
|
//{ name: "Flagstaff, AZ", lat: 35.1983, lon: -111.6513, elevation: 6903 },
|
||||||
@@ -105,30 +90,23 @@ const locations = [
|
|||||||
//{ name: "Ehrenberg, AZ", lat: 33.9897, lon: -114.3550, elevation: 333 },
|
//{ name: "Ehrenberg, AZ", lat: 33.9897, lon: -114.3550, elevation: 333 },
|
||||||
{ name: "Ehrenberg: ++", lat: 33.9897, lon: -114.3550, elevation: 300 },
|
{ name: "Ehrenberg: ++", lat: 33.9897, lon: -114.3550, elevation: 300 },
|
||||||
{ name: "Quartzsite: ++", lat: 33.6763, lon: -114.2104, elevation: 900 },
|
{ name: "Quartzsite: ++", lat: 33.6763, lon: -114.2104, elevation: 900 },
|
||||||
|
{ name: "Kanab: BF", lat: 37.1412, lon: -112.5439, elevation: 5500 },
|
||||||
|
//{ name: "Kanab: ++", lat: 37.1399, lon: -112.5926, elevation: 5700 },
|
||||||
|
{ name: "Pahrump, NV", lat: 36.1925, lon: -115.9758, elevation: 2700 },
|
||||||
];
|
];
|
||||||
locations.sort((a, b) => a.elevation - b.elevation);
|
locations.sort((a, b) => a.elevation - b.elevation);
|
||||||
|
|
||||||
const RED = "\x1b[31m";
|
/* * * Functions * * */
|
||||||
const GRN = "\x1b[32m";
|
|
||||||
const YLW = "\x1b[33m";
|
|
||||||
const BLU = "\x1b[34m";
|
|
||||||
const MGN = "\x1b[35m";
|
|
||||||
const CYN = "\x1b[36m";
|
|
||||||
const WHT = "\x1b[37m";
|
|
||||||
const RESET = "\x1b[0m";
|
|
||||||
|
|
||||||
function highlight(value, min, max) {
|
function highlight(value, min, max) {
|
||||||
const n = parseFloat(value);
|
const n = parseFloat(value);
|
||||||
return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pref_high_upper = 75;
|
function pad(str, width) {
|
||||||
const pref_high_lower = 60;
|
const visible = str.replace(/\x1b\[\d+m/g, '').length;
|
||||||
const pref_low_upper = 55;
|
return ' '.repeat(Math.max(0, width - visible)) + str;
|
||||||
const pref_low_lower = 40;
|
}
|
||||||
|
|
||||||
const tolerance_light = 10;
|
|
||||||
const tolerance_heavy = 20;
|
|
||||||
|
|
||||||
function check (value, min, max) {
|
function check (value, min, max) {
|
||||||
const n = parseFloat(value);
|
const n = parseFloat(value);
|
||||||
@@ -156,11 +134,60 @@ function check (value, min, max) {
|
|||||||
//return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
//return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pad(str, width) {
|
function max (value, upper) {
|
||||||
const visible = str.replace(/\x1b\[\d+m/g, '').length;
|
return (value > upper) ? upper : value;
|
||||||
return ' '.repeat(Math.max(0, width - visible)) + str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* * * Parameters * * */
|
||||||
|
|
||||||
|
const argv = yargs(hideBin(process.argv))
|
||||||
|
.option('days_fore', {
|
||||||
|
alias: 'f',
|
||||||
|
describe: 'Future / forecast days, such as "-f 10". Maximum of 16.',
|
||||||
|
type: 'number',
|
||||||
|
requiresArg: true,
|
||||||
|
})
|
||||||
|
.option('days_past', {
|
||||||
|
alias: 'p',
|
||||||
|
describe: 'Past days, such as "-p 3"',
|
||||||
|
type: 'number',
|
||||||
|
requiresArg: true,
|
||||||
|
})
|
||||||
|
.option('calc_elevation', {
|
||||||
|
alias: 'e',
|
||||||
|
describe: 'Set to calculate elevation at lat/long rather than use supplied.',
|
||||||
|
type: 'boolean',
|
||||||
|
})
|
||||||
|
.check((argv) => {
|
||||||
|
if (argv.f !== undefined && (isNaN(argv.f) || argv.f < 0)) {
|
||||||
|
throw new Error('Forecast days must be a non-negative number');
|
||||||
|
}
|
||||||
|
if (argv.p !== undefined && (isNaN(argv.p) || argv.p < 0)) {
|
||||||
|
throw new Error('Past days must be a non-negative number');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
//.demandOption(['timeout', 'debug']) // Optional: require these arguments
|
||||||
|
.strict()
|
||||||
|
.help()
|
||||||
|
.version(version)
|
||||||
|
.argv
|
||||||
|
;
|
||||||
|
|
||||||
|
/* * * Processing * * */
|
||||||
|
|
||||||
|
const days_fore = max(argv.hasOwnProperty("days_fore") ? argv.days_fore : days_fore_default, days_fore_max);
|
||||||
|
const days_past = argv.hasOwnProperty("days_past") ? argv.days_past : days_past_default;
|
||||||
|
const calc_elevation = argv.calc_elevation ? true : false;
|
||||||
|
|
||||||
|
const days = days_fore + days_past;
|
||||||
|
|
||||||
|
console.log(`Averaging for ${days} days: ${days_fore} forecasted, ${days_past} past.`);
|
||||||
|
if (calc_elevation) console.log("Calculating elevation rather than using provided values.");
|
||||||
|
else console.log("Using user-provided elevations when they exist.");
|
||||||
|
|
||||||
|
/* * * Main * * */
|
||||||
|
|
||||||
async function getForecast(loc) {
|
async function getForecast(loc) {
|
||||||
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
||||||
url.searchParams.set("latitude", loc.lat);
|
url.searchParams.set("latitude", loc.lat);
|
||||||
@@ -213,3 +240,5 @@ async function getForecast(loc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/* * * Finish * * */
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user