File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ fetch_weather_information()
4242# get weather display
4343display_weather ()
4444{
45+   fahrenheit=$1 
4546  if  $fahrenheit ;  then 
4647    display_weather=' &u' #  for USA system
4748  else 
@@ -73,13 +74,24 @@ forecast_unicode()
7374  fi 
7475}
7576
77+ export  -f display_weather
78+ export  -f display_location
79+ export  -f forecast_unicode
80+ export  -f fetch_weather_information
81+ 
7682main ()
7783{
7884  #  process should be cancelled when session is killed
7985  if  timeout 1 bash -c " </dev/tcp/ipinfo.io/443" &&  timeout 1 bash -c " </dev/tcp/wttr.in/443" ;  then 
80-     echo  " $( display_weather) $( display_location) " 
86+     if  !  weather=$( timeout 3 bash -c " display_weather $fahrenheit " ) ;  then 
87+       echo  " Weather Unavailable" 
88+     elif  !  location=$( timeout 3 bash -c display_location) ;  then 
89+       echo  " Location Unavailable" 
90+     else 
91+       echo  " ${weather}${location} " 
92+     fi 
8193  else 
82-     echo  " Weather Unavailable " 
94+     echo  " Network Error " 
8395  fi 
8496}
8597
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ fixedlocation=$3
1111DATAFILE=/tmp/.dracula-tmux-data
1212LAST_EXEC_FILE=" /tmp/.dracula-tmux-weather-last-exec" 
1313RUN_EACH=1200
14+ RETRY_EACH=60
1415TIME_NOW=$( date +%s) 
1516TIME_LAST=$( cat " ${LAST_EXEC_FILE} " 2> /dev/null ||  echo  " 0" ) 
1617
@@ -22,6 +23,10 @@ main()
2223    #  Run weather script here
2324    $current_dir /weather.sh $fahrenheit  $location  " $fixedlocation " >  " ${DATAFILE} " 
2425    echo  " ${TIME_NOW} " >  " ${LAST_EXEC_FILE} " 
26+   elif  grep -q ' Unavailable\|Error' " ${DATAFILE} " &&  [ " $( expr ${TIME_LAST}  + ${RETRY_EACH} ) " -lt  " ${TIME_NOW} " ;  then 
27+     #  Run weather script here
28+     $current_dir /weather.sh $fahrenheit  $location  " $fixedlocation " >  " ${DATAFILE} " 
29+     echo  " ${TIME_NOW} " >  " ${LAST_EXEC_FILE} " 
2530  fi 
2631
2732  cat " ${DATAFILE} " 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments