You are not logged in.

#1 2014-06-18 20:08:58

ObliviousGmn
Member
Registered: 2011-09-14
Posts: 49
Website

[Solved] Weather Script in intervals

Sorry in advance for being noobish, or posting in the wrong thread.

Alright Guys.. I'm having trouble here and I'm a little stumped.
I cut a snippet of the file I'm working on. For a Dzen bar.

...
   WEATHER(){
	Weather=$(Weather 10039)
	printf "${BGC}${FG2}${AL}${BG2} ${FGB}${P}NYC Weather, $Weather${PC}  "
 return
 }
...

What it does, Displays weather to my Dzen bar,
Everything else refreshes in 1 second.
But, I want The Weather only to refresh every 30mins or so.

Any Ideas?


The full code, If anyone wants to see.

#!/bin/bash
# Oblivious June 2014
# Dzen Right Side

# Source
. $HOME/Gmnbox/ZenBash/Settings   

 CPU() {
  Temp=$(sensors | awk '/Core0/ {print +$3}')
  	if [[ "$Temp" -lt "$Cool" ]];
  then 
	printf "${Htop}${BG1}${FG0}${AL}${BG0} ${HTC1}${HT}${CC}  "
  elif
	[[ "$Temp" -le "$Warm" ]];
  then
	printf "${Htop}${BG1}${FG0}${AL}${BG0} ${HTC2}${HT}${CC}  "
  else
	printf "${Htop}${BG1}${FG0}${AL}${BG0} ${HTC3}${HT}${CC}  "
  fi
  return
 }

 HOST() {
	Username=$(printf "$USER" | sed -e "s/\b\(.\)/\u\1/g")
	printf "${BG2}${FG1}${AL}${BG1} ${FGA}${P}${Username}${PC}  "
 return
 }

 WEATHER(){
	Weather=$(Weather 10039)
	printf "${BGC}${FG2}${AL}${BG2} ${FGB}${P}NYC Weather, $Weather${PC}  "
 return
 }

 EDIT() {
	printf "${EditB}     ${CC}${CC}"
 return
 }


while true
do
  sleep 1
	echo "$(EDIT)$(WEATHER)$(HOST)$(CPU)"
  	done | dzen2 -dock -x ${WB} -w ${WB} -h ${HB} -fn ${FN} -bg ${BG} -ta r -p

# End of File

Last edited by ObliviousGmn (2014-06-18 21:22:00)

Offline

#2 2014-06-18 20:31:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [Solved] Weather Script in intervals

Change the while loop:

loops=0
while true; do
   [[ loops -eq 1800 ]] && loops=0
   [[ loops -eq 0 ]] && W=$(WEATHER)
   loops=$(( loops + 1 ))
   echo "$(EDIT)$W$(HOST)$(CPU)"
   sleep 1
done | dzen ...

Last edited by Trilby (2014-06-18 20:32:08)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2014-06-18 20:33:59

ajbibb
Member
Registered: 2012-02-12
Posts: 142

Re: [Solved] Weather Script in intervals

You could have a separate script to call your weather program every 30 minutes and have weather direct output to a temporary file.  In your 1 second refresh script just 'cat' the temporary file.

Offline

#4 2014-06-18 20:37:59

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved] Weather Script in intervals

ajbibb wrote:

You could have a separate script to call your weather program every 30 minutes and have weather direct output to a temporary file.  In your 1 second refresh script just 'cat' the temporary file.

This is exactly what shaman is for...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2014-06-18 21:21:19

ObliviousGmn
Member
Registered: 2011-09-14
Posts: 49
Website

Re: [Solved] Weather Script in intervals

Thank you so much Tribly!

Offline

Board footer

Powered by FluxBB