Skip to content

Instantly share code, notes, and snippets.

@plutozonexyz
Last active August 3, 2020 17:07
Show Gist options
  • Save plutozonexyz/8b2438e76789bd2c708a0c574158f6ef to your computer and use it in GitHub Desktop.
Save plutozonexyz/8b2438e76789bd2c708a0c574158f6ef to your computer and use it in GitHub Desktop.
automated front-end to wttr.in
#!/bin/sh
if [ "$1" == "" ]; then
if [ -f ~/.wttrrc ]; then
curl `echo -n "https://wttr.in/";head -n 1 ~/.wttrrc | tr -d "\n";echo -n "?";head -n 2 ~/.wttrrc | tail -n 1 | tr -d "\n";echo -n "&format=";tail -n 1 ~/.wttrrc | tr -d "\n"`
elif [ -f ~/.config/wttrrc ]; then
curl `echo -n "https://wttr.in/";head -n 1 ~/.config/wttrrc | tr -d "\n";echo -n "?";head -n 2 ~/.config/wttrrc | tail -n 1 | tr -d "\n";echo -n "&format=";tail -n 1 ~/.config/wttrrc | tr -d "\n"`
else
echo "If you are to use weather without a .wttrrc in your ~ (or without a ~/.config/wttrrc), please refer to the '--help' flag for creating a .wttrrc."
fi
elif [ "$1" == "--help" ]; then
echo -e "
.wttrrc syntax (line by line):
1: [ZIP/Postal Code] [ex. '17025']
2: [Unit of Measurement]
['m' for Metric/SI, 'u' for USCS/USA] [ex. 'u']
3: [Format] [ex. '%l:+%c+%t\\\n']
[
Table of format codes [Must be prefixed with %]:
c Weather condition, [UNICODE]
C Weather condition textual name,
h Humidity,
t Temperature (Actual),
f Temperature (Feels Like),
w Wind,
l Location,
m Moonphase [UNICODE]
M Moonday,
p precipitation (mm),
o Probability of Precipitation,
P pressure (hPa),
There are also 2 special codes that need not be prefixed by %:
+ [ASCII Space]
\\\n [ASCII Newline]
!!! Remember to put a newline at the end of all formats !!!
]
"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment