9front - general discussion about 9front
 help / color / mirror / Atom feed
From: kemal <kemali13@protonmail.com>
To: "9front@9front.org" <9front@9front.org>
Subject: [9front] weather: rewrite with a new api
Date: Sat, 03 Apr 2021 20:33:32 +0000	[thread overview]
Message-ID: <SB83GPQSKObdqs3fwEpBunAwxxFL6nTuKv-4Dy2F1eC74FyLodsEr455ll99ikZoWOhYJs4clZl0_DT55klNj_nTtHcdvpv5c0gVcO0NiTE=@protonmail.com> (raw)

hello,

i have written a new "weather" script using a different api.
old version was using telnet and stopped receiving updates,
this one uses http with hget instead and has recent weather.

diff -r cc26fdf57bb2 rc/bin/weather
--- a/rc/bin/weather	Sat Mar 13 14:57:53 2021 +0100
+++ b/rc/bin/weather	Sat Apr 03 23:31:49 2021 +0300
@@ -1,46 +1,9 @@
 #!/bin/rc
-
-rfork e
-
-DEFAULT=ewr
-
-fn usage{
-	echo 'usage: weather 3-letter-city-code' >[1=2]
-	echo 'for a list of cities in new york, say' >[1=2]
-	echo '	weather ny' >[1=2]
-	exit usage
-}
-
-switch($#*){
-case 0
-	arg=$DEFAULT
-	if(~ $#weather 1)
-		arg=$weather
-case 1
-	arg=$1
-case *
-	usage
-}
-
-switch($arg){
-case [a-zA-Z][a-zA-Z][a-zA-Z]
-	script=('' '' 'C' '4' '1' '1' $arg '' '' '' '' 'X')
-case [a-zA-Z][a-zA-Z]
-	script=('' '' 'C' '4' '1' '3' $arg '' '' '' '' 'X')
-case *
-	usage
-}
-
-{
-	for(i in $script)
-		echo $i
-} |
-con -nrl tcp!rainmaker.wunderground.com!telnet |
-sed -n '/Enter .-letter .* code:/,/CITY FORECAST MENU/p' |
-sed 's/Enter .-letter .* code: //' |
-sed 's/   Press Return to continue, M to return to menu, X to exit: //' |
-grep -v 'CITY FORECAST MENU' |
-tr -d '
' |
-sed 's/ *$//' |
-uniq |
-sed -n '/^VTEC/q; p'
+loc=''
+if (! ~ $#* 0)
+	loc=`{echo $* | sed 's/ +/+/g'}
+if not
+	if (! ~ $#weather 0)
+		loc=$weather
+hget https://wttr.in/$loc?TA0
+echo
diff -r cc26fdf57bb2 sys/man/1/weather
--- a/sys/man/1/weather	Sat Mar 13 14:57:53 2021 +0100
+++ b/sys/man/1/weather	Sat Apr 03 23:31:49 2021 +0300
@@ -4,37 +4,24 @@
 .SH SYNOPSIS
 .B weather
 [
-.I air
-]  [
-.I st
+.I location
 ]
 .SH DESCRIPTION
 .I Weather
-prints the local conditions and seven-day forecast most recently reported at the
-.SM US
-airport with the three-letter location identifier
-.IR air .
-Given a two-letter
-.SM US
-state abbreviation
-.I st
-instead,
-.I weather
-prints a table of
-.I air
-location identifiers known for
-.IR st .
-.PP
-The arguments are mutually exclusive and case-insensitive.
-If neither is given,
-.I air
-defaults to the value of the environment variable
-.BR $weather ,
-or if it is unset,
-to the location identifier
-.BR ewr ,
-designating the Newark, NJ, airport near Bell Labs, Murray Hill.
+by using wttr.in prints the local conditions most recently reported at the given
+.IR location ,
+the enviroment variable
+.B $weather
+or at detected location if neither are given.
+Any location (area codes, airport codes, any location names) usually works.
+Some special places might require putting a tilde
+.RB ( ~ )
+at the beginning. Weather of IP adresses or domain names can be found by typing an at sign
+.RB ( @ )
+the beginning. Location format can change, see https://wttr.in/:help for more info.
 .SH SOURCE
 .B /rc/bin/weather
 .SH BUGS
 Weather is hopelessly provincial.
+
+Redesigns of the wttr.in API might break this program.


             reply	other threads:[~2021-04-03 21:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-03 20:33 kemal [this message]
2021-04-05 11:26 ` Sigrid Solveig Haflínudóttir
2021-04-05 11:50   ` kemal
2021-04-05 12:13     ` hiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='SB83GPQSKObdqs3fwEpBunAwxxFL6nTuKv-4Dy2F1eC74FyLodsEr455ll99ikZoWOhYJs4clZl0_DT55klNj_nTtHcdvpv5c0gVcO0NiTE=@protonmail.com' \
    --to=kemali13@protonmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).