fixing weather script to remove api key need
This commit is contained in:
		
							parent
							
								
									d36f93999b
								
							
						
					
					
						commit
						3027153951
					
				
							
								
								
									
										48
									
								
								bin/weather/consts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								bin/weather/consts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					    "113": "Sunny",
 | 
				
			||||||
 | 
					    "116": "PartlyCloudy",
 | 
				
			||||||
 | 
					    "119": "Cloudy",
 | 
				
			||||||
 | 
					    "122": "VeryCloudy",
 | 
				
			||||||
 | 
					    "143": "Fog",
 | 
				
			||||||
 | 
					    "176": "LightShowers",
 | 
				
			||||||
 | 
					    "179": "LightSleetShowers",
 | 
				
			||||||
 | 
					    "182": "LightSleet",
 | 
				
			||||||
 | 
					    "185": "LightSleet",
 | 
				
			||||||
 | 
					    "200": "ThunderyShowers",
 | 
				
			||||||
 | 
					    "227": "LightSnow",
 | 
				
			||||||
 | 
					    "230": "HeavySnow",
 | 
				
			||||||
 | 
					    "248": "Fog",
 | 
				
			||||||
 | 
					    "260": "Fog",
 | 
				
			||||||
 | 
					    "263": "LightShowers",
 | 
				
			||||||
 | 
					    "266": "LightRain",
 | 
				
			||||||
 | 
					    "281": "LightSleet",
 | 
				
			||||||
 | 
					    "284": "LightSleet",
 | 
				
			||||||
 | 
					    "293": "LightRain",
 | 
				
			||||||
 | 
					    "296": "LightRain",
 | 
				
			||||||
 | 
					    "299": "HeavyShowers",
 | 
				
			||||||
 | 
					    "302": "HeavyRain",
 | 
				
			||||||
 | 
					    "305": "HeavyShowers",
 | 
				
			||||||
 | 
					    "308": "HeavyRain",
 | 
				
			||||||
 | 
					    "311": "LightSleet",
 | 
				
			||||||
 | 
					    "314": "LightSleet",
 | 
				
			||||||
 | 
					    "317": "LightSleet",
 | 
				
			||||||
 | 
					    "320": "LightSnow",
 | 
				
			||||||
 | 
					    "323": "LightSnowShowers",
 | 
				
			||||||
 | 
					    "326": "LightSnowShowers",
 | 
				
			||||||
 | 
					    "329": "HeavySnow",
 | 
				
			||||||
 | 
					    "332": "HeavySnow",
 | 
				
			||||||
 | 
					    "335": "HeavySnowShowers",
 | 
				
			||||||
 | 
					    "338": "HeavySnow",
 | 
				
			||||||
 | 
					    "350": "LightSleet",
 | 
				
			||||||
 | 
					    "353": "LightShowers",
 | 
				
			||||||
 | 
					    "356": "HeavyShowers",
 | 
				
			||||||
 | 
					    "359": "HeavyRain",
 | 
				
			||||||
 | 
					    "362": "LightSleetShowers",
 | 
				
			||||||
 | 
					    "365": "LightSleetShowers",
 | 
				
			||||||
 | 
					    "368": "LightSnowShowers",
 | 
				
			||||||
 | 
					    "371": "HeavySnowShowers",
 | 
				
			||||||
 | 
					    "374": "LightSleetShowers",
 | 
				
			||||||
 | 
					    "377": "LightSleet",
 | 
				
			||||||
 | 
					    "386": "ThunderyShowers",
 | 
				
			||||||
 | 
					    "389": "ThunderyHeavyRain",
 | 
				
			||||||
 | 
					    "392": "ThunderySnowShowers",
 | 
				
			||||||
 | 
					    "395": "HeavySnowShowers",
 | 
				
			||||||
							
								
								
									
										40
									
								
								bin/weather/symbols
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								bin/weather/symbols
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					# day
 | 
				
			||||||
 | 
					Unkown              '\ue374'
 | 
				
			||||||
 | 
					Cloudy              '\ue302'
 | 
				
			||||||
 | 
					Fog                 '\ue303'
 | 
				
			||||||
 | 
					HeavyRain           '\ue318'
 | 
				
			||||||
 | 
					HeavyShowers        '\ue318'
 | 
				
			||||||
 | 
					HeavySnow           '\ue31a'
 | 
				
			||||||
 | 
					HeavySnowShowers    '\ue31a'
 | 
				
			||||||
 | 
					LightRain           '\ue308'
 | 
				
			||||||
 | 
					LightShowers        '\ue308'
 | 
				
			||||||
 | 
					LightSleet          '\ue3aa'
 | 
				
			||||||
 | 
					LightSleetShowers   '\ue3aa'
 | 
				
			||||||
 | 
					LightSnow           '\ue30a'
 | 
				
			||||||
 | 
					LightSnowShowers    '\ue30a'
 | 
				
			||||||
 | 
					PartlyCloudy        '\ue37b'
 | 
				
			||||||
 | 
					Sunny               '\ue30d'
 | 
				
			||||||
 | 
					ThunderyHeavyRain   '\ue31d'
 | 
				
			||||||
 | 
					ThunderyShowers     '\ue31d'
 | 
				
			||||||
 | 
					ThunderySnowShowers '\ue365'
 | 
				
			||||||
 | 
					VeryCloudy          '\ue312'
 | 
				
			||||||
 | 
					# night
 | 
				
			||||||
 | 
					Unkown              '\ue374'
 | 
				
			||||||
 | 
					Cloudy              '\ue37e'
 | 
				
			||||||
 | 
					Fog                 '\ue346'
 | 
				
			||||||
 | 
					HeavyRain           '\ue318'
 | 
				
			||||||
 | 
					HeavyShowers        '\ue318'
 | 
				
			||||||
 | 
					HeavySnow           '\ue31a'
 | 
				
			||||||
 | 
					HeavySnowShowers    '\ue31a'
 | 
				
			||||||
 | 
					LightRain           '\ue325'
 | 
				
			||||||
 | 
					LightShowers        '\ue325'
 | 
				
			||||||
 | 
					LightSleet          '\ue3ac'
 | 
				
			||||||
 | 
					LightSleetShowers   '\ue3ac'
 | 
				
			||||||
 | 
					LightSnow           '\ue361'
 | 
				
			||||||
 | 
					LightSnowShowers    '\ue361'
 | 
				
			||||||
 | 
					PartlyCloudy        '\ue379'
 | 
				
			||||||
 | 
					Sunny               '\ue32b'
 | 
				
			||||||
 | 
					ThunderyHeavyRain   '\ue31d'
 | 
				
			||||||
 | 
					ThunderyShowers     '\ue31d'
 | 
				
			||||||
 | 
					ThunderySnowShowers '\ue366'
 | 
				
			||||||
 | 
					VeryCloudy          '\ue312'
 | 
				
			||||||
							
								
								
									
										46
									
								
								bin/weather/symbols.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								bin/weather/symbols.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# source symbol based on $WEATHER_CODE and $TOD
 | 
				
			||||||
 | 
					# WeatherCodesDay := map[string]rune{
 | 
				
			||||||
 | 
					# "Unkown":              '\ue374',
 | 
				
			||||||
 | 
					# "Cloudy":              '\ue302',
 | 
				
			||||||
 | 
					# "Fog":                 '\ue303',
 | 
				
			||||||
 | 
					# "HeavyRain":           '\ue318',
 | 
				
			||||||
 | 
					# "HeavyShowers":        '\ue318',
 | 
				
			||||||
 | 
					# "HeavySnow":           '\ue31a',
 | 
				
			||||||
 | 
					# "HeavySnowShowers":    '\ue31a',
 | 
				
			||||||
 | 
					# "LightRain":           '\ue308',
 | 
				
			||||||
 | 
					# "LightShowers":        '\ue308',
 | 
				
			||||||
 | 
					# "LightSleet":          '\ue3aa',
 | 
				
			||||||
 | 
					# "LightSleetShowers":   '\ue3aa',
 | 
				
			||||||
 | 
					# "LightSnow":           '\ue30a',
 | 
				
			||||||
 | 
					# "LightSnowShowers":    '\ue30a',
 | 
				
			||||||
 | 
					# "PartlyCloudy":        '\ue37b',
 | 
				
			||||||
 | 
					# "Sunny":               '\ue30d',
 | 
				
			||||||
 | 
					# "ThunderyHeavyRain":   '\ue31d',
 | 
				
			||||||
 | 
					# "ThunderyShowers":     '\ue31d',
 | 
				
			||||||
 | 
					# "ThunderySnowShowers": '\ue365',
 | 
				
			||||||
 | 
					# "VeryCloudy":          '\ue312',
 | 
				
			||||||
 | 
					# }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# WeatherCodesNight := map[string]rune{
 | 
				
			||||||
 | 
					# "Unkown":              '\ue374',
 | 
				
			||||||
 | 
					# "Cloudy":              '\ue37e',
 | 
				
			||||||
 | 
					# "Fog":                 '\ue346',
 | 
				
			||||||
 | 
					# "HeavyRain":           '\ue318',
 | 
				
			||||||
 | 
					# "HeavyShowers":        '\ue318',
 | 
				
			||||||
 | 
					# "HeavySnow":           '\ue31a',
 | 
				
			||||||
 | 
					# "HeavySnowShowers":    '\ue31a',
 | 
				
			||||||
 | 
					# "LightRain":           '\ue325',
 | 
				
			||||||
 | 
					# "LightShowers":        '\ue325',
 | 
				
			||||||
 | 
					# "LightSleet":          '\ue3ac',
 | 
				
			||||||
 | 
					# "LightSleetShowers":   '\ue3ac',
 | 
				
			||||||
 | 
					# "LightSnow":           '\ue361',
 | 
				
			||||||
 | 
					# "LightSnowShowers":    '\ue361',
 | 
				
			||||||
 | 
					# "PartlyCloudy":        '\ue379',
 | 
				
			||||||
 | 
					# "Sunny":               '\ue32b',
 | 
				
			||||||
 | 
					# "ThunderyHeavyRain":   '\ue31d',
 | 
				
			||||||
 | 
					# "ThunderyShowers":     '\ue31d',
 | 
				
			||||||
 | 
					# "ThunderySnowShowers": '\ue366',
 | 
				
			||||||
 | 
					# "VeryCloudy":          '\ue312',
 | 
				
			||||||
 | 
					# }
 | 
				
			||||||
							
								
								
									
										112
									
								
								bin/weather/wttr
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										112
									
								
								bin/weather/wttr
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,112 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					usage() {
 | 
				
			||||||
 | 
					    cat <<EOF
 | 
				
			||||||
 | 
					Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Queries the weather and outputs it in a Nerd Font compaitable way
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Options:
 | 
				
			||||||
 | 
					  -s, --setloc=<LOC>    change location used for wttr.in query
 | 
				
			||||||
 | 
					                          clears disploc on set
 | 
				
			||||||
 | 
					  -d, --disploc=<LOC>   set a location name to display instead of the 
 | 
				
			||||||
 | 
					                          location used in wttr.in query
 | 
				
			||||||
 | 
					  -u, --unit={c|f}      set the output unit to fahrenheit or celsius
 | 
				
			||||||
 | 
					  -i, --info            shows current values of location, unit and
 | 
				
			||||||
 | 
					                          disploc if it is set
 | 
				
			||||||
 | 
					  -f, --force           force refresh weather data
 | 
				
			||||||
 | 
					  -h, --help            Show this help message
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					exit 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					get_tod() {
 | 
				
			||||||
 | 
					    # sets $TOD
 | 
				
			||||||
 | 
					    hour=$(date +%H)
 | 
				
			||||||
 | 
					    if [[ $hour -gt 21 || $hour -lt 5 ]] ; then # between 9 pm and 5 am
 | 
				
			||||||
 | 
					        TOD="night"
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        TOD="day"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					get_wttr() {
 | 
				
			||||||
 | 
					    # gets weather for $LOCATION and stores it into file with timestamp
 | 
				
			||||||
 | 
					    url="https://wttr.in/$LOCATION?0&format=j2" #json stuff need to fix temp
 | 
				
			||||||
 | 
					    query="{\
 | 
				
			||||||
 | 
					        temp:       .current_condition[0].temp_F,\
 | 
				
			||||||
 | 
					        humidity:   .current_condition[0].humidity,\
 | 
				
			||||||
 | 
					        conditions: .current_condition[0].weatherCode,\
 | 
				
			||||||
 | 
					        location:   .nearest_area[0].areaName[0].value}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    WTTR=$(curl --silent -fL "$url" | gojq "$query")
 | 
				
			||||||
 | 
					    echo "$WTTR"
 | 
				
			||||||
 | 
					    #TEMP=$(echo "$WTTR" | gojq -r '.temp_F')
 | 
				
			||||||
 | 
					    #HUMIDITY=$(echo "$WTTR" | gojq -r '.humidity')
 | 
				
			||||||
 | 
					    #CONDITIONS=$(echo "$WTTR" | gojq -r '.weatherDesc[0].value')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set_location() {
 | 
				
			||||||
 | 
					    # updates location of weather query to $new_loc
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					display_location() {
 | 
				
			||||||
 | 
					    # updates location to display to $disp_loc
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set_units() {
 | 
				
			||||||
 | 
					    # updates units used to $unit
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					display_info() {
 | 
				
			||||||
 | 
					    # prints current config to stdout
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					update_wttr() {
 | 
				
			||||||
 | 
					    # checks to see if old weather data is out of date
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print_wttr() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    echo "TODO"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while [[ "$1" != "" ]]; do
 | 
				
			||||||
 | 
					    case $1 in
 | 
				
			||||||
 | 
					    -h | --help)
 | 
				
			||||||
 | 
					        usage
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    -s | --setloc)
 | 
				
			||||||
 | 
					        shift
 | 
				
			||||||
 | 
					        new_loc="$1"
 | 
				
			||||||
 | 
					        set_location
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    -d | --disploc)
 | 
				
			||||||
 | 
					        shift
 | 
				
			||||||
 | 
					        disp_loc="$1"
 | 
				
			||||||
 | 
					        display_location
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    -u | --unit)
 | 
				
			||||||
 | 
					        shift
 | 
				
			||||||
 | 
					        unit="$1"
 | 
				
			||||||
 | 
					        set_units
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    -i | --info)
 | 
				
			||||||
 | 
					        display_info
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    -f | --force)
 | 
				
			||||||
 | 
					        get_wttr
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    *)
 | 
				
			||||||
 | 
					        echo "Error: wttr $@"
 | 
				
			||||||
 | 
					        usage
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					    shift
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
@ -1,15 +0,0 @@
 | 
				
			|||||||
#!/usr/bin/env bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
HOUR=$(timedatectl | grep Local | cut -d ':' -f 2 | cut -d ' ' -f 4 | cut -d ':' -f 1)
 | 
					 | 
				
			||||||
if [[ ${HOUR} -gt 21 || ${HOUR} -lt 5 ]] ; then # between 9 pm and 5 am
 | 
					 | 
				
			||||||
    TIME_OF_DAY="NIGHT"
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
    TIME_OF_DAY="DAY"
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
URL=$(printf 'https://v2%s.wttr.in?0&format=j1&nonce=$RANDOM' $TOD)
 | 
					 | 
				
			||||||
WTTR=$(curl --silent -fL $URL)
 | 
					 | 
				
			||||||
TMP=$(echo $WTTR | jq -r '.current_condition[0]')
 | 
					 | 
				
			||||||
TEMP=$(echo $TMP | jq -r '.temp_F')
 | 
					 | 
				
			||||||
HUMIDITY=$(echo $TMP | jq -r '.humidity')
 | 
					 | 
				
			||||||
CONDITIONS=$(echo $TMP | jq -r '.weatherDesc[0].value')
 | 
					 | 
				
			||||||
echo $TEMP $HUMIDITY $CONDITIONS
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user