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
+66
-30
@@ -5,10 +5,12 @@
|
||||
## Variables ##
|
||||
|
||||
DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||
PROJ="$(cd "$DIR"/.. &>/dev/null && pwd)"
|
||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
LOCAL=~/bin
|
||||
GLOBAL=/usr/local/bin
|
||||
GLOBAL_SRC=/usr/local/src
|
||||
GLOBAL="/usr/local"
|
||||
GLOBAL_BIN="$GLOBAL/bin"
|
||||
GLOBAL_SRC="$GLOBAL/src"
|
||||
|
||||
name_local="prototype.js"
|
||||
name_short="nomad"
|
||||
@@ -19,88 +21,122 @@ name_abs="weather-list"
|
||||
|
||||
function usage {
|
||||
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.
|
||||
|
||||
Parameters)
|
||||
h) Display this message.
|
||||
g) Install globally ($GLOBAL), otherwise local ($LOCAL).
|
||||
a) Abstract name, unrelated to being nomadic. ($name_abs)
|
||||
l) Long name, the full name of the project. ($name_long)
|
||||
a) All names / pseudonyms, rather than choosing from below.
|
||||
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)
|
||||
r) Remove / uninstall the project according to the above flags.
|
||||
|
||||
Examples)
|
||||
- Install to the local user with the abstract name.
|
||||
- Install to the local user with the default name.
|
||||
$PROG
|
||||
- Install to all users with all names.
|
||||
$PROG -alsg
|
||||
$PROG -ga
|
||||
- Remove all instances.
|
||||
$PROG -alsr && $PROG -alsrg
|
||||
$PROG -ra && $PROG -gra
|
||||
|
||||
Happy weather watching! :)
|
||||
|
||||
~ Hyperling
|
||||
|
||||
https://git.hyperling.com/me/nomadic-weather
|
||||
EOF
|
||||
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 ##
|
||||
|
||||
while getopts ":gslarh" arg; do
|
||||
while getopts ":gslabrh" arg; do
|
||||
case $arg in
|
||||
g) global="Y" ;;
|
||||
s) short="Y" ;;
|
||||
l) long="Y" ;;
|
||||
a) abstract="Y" ;;
|
||||
b) abstract="Y" ;;
|
||||
a) all="Y" ;;
|
||||
r) remove="Y" ;;
|
||||
h) usage ;;
|
||||
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
## Processing ##
|
||||
|
||||
name=""
|
||||
if [[ "$short" == "Y" ]]; then
|
||||
name="$name $name_short"
|
||||
fi
|
||||
if [[ "$long" == "Y" ]]; then
|
||||
name="$name $name_long"
|
||||
fi
|
||||
if [[ "$abstract" == "Y" || ( -z "$short" && -z "$long" ) ]]; then
|
||||
if [[ "$all" == "Y" || "$abstract" == "Y" ]]; then
|
||||
name="$name $name_abs"
|
||||
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=""
|
||||
dir="$LOCAL"
|
||||
src="$DIR"
|
||||
src="$PROJ"
|
||||
if [[ "$global" == "Y" ]]; then
|
||||
dir="$GLOBAL"
|
||||
cmd="sudo"
|
||||
dir="$GLOBAL_BIN"
|
||||
src="$GLOBAL_SRC/`basename "$PROJ"`"
|
||||
echo "Requesting sudo privileges... "
|
||||
sudo echo "Success!"
|
||||
mkdir -pv /usr/local/src
|
||||
sudo cp -Rv "$DIR" $GLOBAL_SRC/
|
||||
src="$GLOBAL_SRC/`basename "$DIR"`"
|
||||
fi
|
||||
|
||||
if [[ -z "$remove" ]]; then
|
||||
cmd="$cmd ln -svf $src/$name_local"
|
||||
cmd="$cmd ln -svf $src/cli/$name_local"
|
||||
else
|
||||
cmd="$cmd rm -v"
|
||||
fi
|
||||
|
||||
## Main ##
|
||||
|
||||
# Untested
|
||||
#if [[ "$global" == "Y" && "$remove" == "Y" ]]; then
|
||||
# sudo rm -rfv "$src"
|
||||
#fi
|
||||
# Global Source Code: Install / Removal
|
||||
if [[ "$global" == "Y" ]]; then
|
||||
if [[ "$remove" == "Y" ]]; then
|
||||
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
|
||||
mkdir -pv "$dir"
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -pv "$dir"
|
||||
fi
|
||||
$cmd "$dir/$prog"
|
||||
done
|
||||
|
||||
|
||||
Vendored
+94
-65
@@ -23,63 +23,48 @@
|
||||
* - 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 { hideBin } = require('yargs/helpers');
|
||||
|
||||
const version = '0.0.1';
|
||||
/* * * Variables * * */
|
||||
|
||||
const version = '0.1.2';
|
||||
|
||||
const days_fore_max = 16;
|
||||
const days_fore_default = 12;
|
||||
const days_past_default = 2;
|
||||
const days_fore_default = 7;
|
||||
const days_past_default = 7;
|
||||
|
||||
const ft_to_m = 0.3048;
|
||||
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.option('days_fore', {
|
||||
alias: 'f',
|
||||
describe: 'Set forecast days, such as "-f 10". Maximum of 16.',
|
||||
type: 'number',
|
||||
requiresArg: true,
|
||||
})
|
||||
.option('days_past', {
|
||||
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
|
||||
;
|
||||
const RED = "\x1b[31m";
|
||||
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 max (value, upper) {
|
||||
return (value > upper) ? upper : value;
|
||||
}
|
||||
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 pref_high_upper = 75;
|
||||
const pref_high_lower = 60;
|
||||
const pref_low_upper = 55;
|
||||
const pref_low_lower = 40;
|
||||
|
||||
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.");
|
||||
const tolerance_light = 10;
|
||||
const tolerance_heavy = 20;
|
||||
|
||||
const locations = [
|
||||
//{ 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: ++", lat: 33.9897, lon: -114.3550, elevation: 300 },
|
||||
{ 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);
|
||||
|
||||
const RED = "\x1b[31m";
|
||||
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";
|
||||
/* * * Functions * * */
|
||||
|
||||
function highlight(value, min, max) {
|
||||
const n = parseFloat(value);
|
||||
return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
||||
}
|
||||
|
||||
const pref_high_upper = 75;
|
||||
const pref_high_lower = 60;
|
||||
const pref_low_upper = 55;
|
||||
const pref_low_lower = 40;
|
||||
|
||||
const tolerance_light = 10;
|
||||
const tolerance_heavy = 20;
|
||||
function pad(str, width) {
|
||||
const visible = str.replace(/\x1b\[\d+m/g, '').length;
|
||||
return ' '.repeat(Math.max(0, width - visible)) + str;
|
||||
}
|
||||
|
||||
function check (value, min, max) {
|
||||
const n = parseFloat(value);
|
||||
@@ -156,11 +134,60 @@ function check (value, min, max) {
|
||||
//return (n >= min && n <= max) ? `${GRN}${value}${RESET}` : value;
|
||||
}
|
||||
|
||||
function pad(str, width) {
|
||||
const visible = str.replace(/\x1b\[\d+m/g, '').length;
|
||||
return ' '.repeat(Math.max(0, width - visible)) + str;
|
||||
function max (value, upper) {
|
||||
return (value > upper) ? upper : value;
|
||||
}
|
||||
|
||||
/* * * 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) {
|
||||
const url = new URL("https://api.open-meteo.com/v1/forecast");
|
||||
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