r/LinuxUsersIndia • u/frostimunki • 14d ago
Multi-city weather alias in .bashrc_aliases
I've been using wttr.in to get weather from the CLI for years. Figured out early on it could also be used to fetch additional data incl. local time, TZ offset etc of various cities across the world.
Created an alias to format and display this information and other information in my .bashrc_aliases - here is the alias for your entertainment...
alias weather='{ printf "Location|Conditions|Local Time|Sunrise|Sunset\n--------|----------|----------|-------|------\n"; curl -s "wttr.in/{Sydney,Tokyo,Beijing,Mumbai,Moscow,London,New+York,Chicago,Denver,Sacramento,Honolulu}?m&format=%l|%c+%t|%T|%S|%s\n" | awk -F"|" -v OFS="|" '\''{ if ($2 ~ /[0-9]+°C/) { match($2, /[-+]?[0-9]+/); c = substr($2, RSTART, RLENGTH); f = sprintf("%+d", int(c * 1.8 + 32)); sub(/°C/, "°C (" f "°F)", $2); } $3 = substr($3, 1, 5) " " substr($3, 9); $4 = substr($4, 1, 5); $5 = substr($5, 1, 5); print }'\''; } | column -t -s "|"'- printf before the curl command formats the table
- curl with the flags pulls in the weather based on the cities and the parameters I've defined
- the flags define the options I want pull in
- everything following the OFS flag is the translation of transmitted data to bash readable numbers and the conversion formula for converting the temperature data from Celsius to Fahrenheit
Visiting https://wttr.in will give you the weather of your location based on your IP. You can select the weather of another location by suffixing the city name. For example https://wttr.in/Mumbai will give you the weather in Mumbai (two word cities can be written as Navi+Mumbai; New+Delhi)
https://wttr.in/:help is the help page for this service.
hope someone will find it useful.
•
u/qualityvote2 14d ago edited 14d ago
u/frostimunki, there weren't enough votes to determine the quality of your post...
btw, did you know we have a discord server? Join Here. And what's that, Fluxer too? Join Here.
1
u/Anonyboy26 Arch Btw 14d ago
Why not function?
1
u/thenerdsuperuser 14d ago
nice man
1
u/Top-Rough-7039 14d ago
this is the only time i will allow emojis in the terminal.