Advertisement
FreewheelinFrank

GenMon weather script

Sep 9th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | Software | 0 0
  1. #!/bin/bash
  2. #dontsurfinthenude.blogspot.com/
  3.  
  4. location=wolverhampton,gb
  5. #try city,country code or look up at openweathermap.org
  6. data_metric=$(ansiweather -l $location -u metric -s true -a false -d true)
  7. data_imperial=$(ansiweather -l $location -u imperial -s true -a false -d true)
  8. #comment out one if you want only metric or only imperial
  9. data7day=$(ansiweather -l $location -u metric -s true -a false -f 7) #centigrade
  10. #data7day=$(ansiweather -l $location -u imperial -s true -a false -f 7) #fahrenheit
  11.  
  12. city=$(echo "$data_metric" | awk '{print $3}')
  13. temp=$(echo "$data_metric" | awk '{print $4$5}') #city,temp,°C
  14. #temp=$(echo "$data_imperial" | awk '{print $5$6}') #city,temp,°F
  15. symbol=$(echo "$data_metric" | awk '{print $6}')
  16. #wind=$(echo "$data_metric" | awk '{print $9,$11,$12,$13}') #wind,m/s
  17. wind=$(echo "$data_imperial" | awk '{print $9,$11,$12,$13}') #wind,mph
  18. humidity=$(echo "$data_imperial" | awk '{print $15,$17$18}') #humidity
  19. pressure=$(echo "$data_metric" | awk '{print $20,$22,$23}') #pressure,hPa
  20. #pressure=$(echo "$data_imperial" | awk '{print $20,$22,$23}') #pressure,inHg
  21. sunrise=$(echo "$data_metric" | awk '{printf "%7s %.5s %s\n", $23,$26,$27}') #sunrise
  22. sunset=$(echo "$data_metric" | awk '{printf "%-7s %.5s %s\n", $29,$32,$33}') #sunset
  23.  
  24. forecast=$(echo "$data7day" | awk 'BEGIN {format="%s %7s%s %s\n"} #7-day-forcast
  25. {printf format, $3,$6,$7,$8}
  26. {printf format, $10,$13,$14,$15}
  27. {printf format, $17,$20,$21,$22}
  28. {printf format, $24,$27,$28,$29}
  29. {printf format, $31,$34,$35,$36}
  30. {printf format, $38,$41,$42,$43}
  31. {printf format, $45,$48,$49,$50}')
  32.  
  33.  
  34. PANEL="<txt>$temp</txt>"
  35. PANEL+="<txtclick>firefox --new-tab --url https://openweathermap.org/city/2633691</txtclick>"
  36. #PANEL+="<txtclick>xfce4-panel --plugin-event=genmon-*:refresh:bool:true</txtclick>"
  37. #Replace "*" with the ID number from the XFCE panel - Preferences>Items (Hover)
  38. #PANEL+="<txtclick>xterm -hold -e ansiweather -l $location -s true -f 7</txtclick>"
  39.  
  40. TOOLTIP="<tool>"
  41. TOOLTIP+="<span weight='bold' font='sans regular'>W E A T H E R</span>\n\n"
  42. TOOLTIP+="<span font= 'sans regular'>$city</span>\n"
  43. TOOLTIP+="Now: $temp $symbol\n\n"
  44. #TOOLTIP+="<span font= 'sans regular'>$wind</span>\n"
  45. #TOOLTIP+="<span font= 'sans regular'>$humidity</span>\n"
  46. #TOOLTIP+="<span font= 'sans regular'>$pressure</span>\n\n"
  47. TOOLTIP+="<span font= 'monospace regular'>$forecast</span>\n\n"
  48. TOOLTIP+="<span font= 'sans regular'>$sunrise</span>\n"
  49. TOOLTIP+="<span font= 'sans regular'>$sunset</span>\n\n"
  50. #TOOLTIP+="<span weight='bold' font='sans regular'>Click to update</span>"
  51. TOOLTIP+="<span weight='bold' font='sans regular'>OpenWeather</span>"
  52. TOOLTIP+="</tool>"
  53.  
  54.  
  55. if [[ -z "$data7day" || "$data7day" == "ERROR: Cannot fetch weather data" ]]; then
  56.  
  57. echo "<icon>network-offline</icon>"
  58. echo "<tool>No Internet</tool>"
  59. else
  60. echo -e "${PANEL}"
  61. echo -e "${TOOLTIP}"
  62. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement