Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jmar71n/1009033 to your computer and use it in GitHub Desktop.
Save jmar71n/1009033 to your computer and use it in GitHub Desktop.
Location updater script for laptop users using gnome-shell-extension-weather. Script gets location based on surrounding wireless access points, then converts that into a woeid.
#!/bin/bash
# gnome-shell-extension-weather-location-updater.sh is free software: you
# can redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
#
# gnome-shell-extension-weather-location-updater.sh is distributed in the hope
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
WIRELESS_INTERFACE=eth1
#Currently only gets first AP (should get all)
ACCESS_POINTS=$(
iwlist $WIRELESS_INTERFACE scan \
| grep Address \
| head -1 \
| sed 's/.*: //'
)
REQUEST=$(
/bin/echo '{"version":"1.1.0","host":"maps.google.com","request_address":true,"address_language":"en_GB","wifi_towers":[{"mac_address":"$ACCESS_POINTS","signal_strength":8,"age":0}]}'
)
# Use Google API to get coordinates from surrounding wireless access points.
LOCATION=$(
wget -q --post-data="$REQUEST" -O - http://www.google.com/loc/json \
| sed -e 's/{/\n/g' -e 's/,/\n/g'
)
LATITUDE=$(echo $LOCATION | awk '{print $2}' | sed 's/.*://g')
LONGITUDE=$(echo $LOCATION | awk '{print $3}' | sed 's/.*://g')
# Use Yahoo API to get WOEID from longitude/latitude.
WOEID=$(
curl --silent http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.placefinder%20where%20text%3D%22$LATITUDE%2C$LONGITUDE%22%20and%20gflags%3D%22R%22 \
| grep woeid \
| sed -e s'/.*<woeid>//' -e 's/<\/woeid>.*//'
)
gsettings set org.gnome.shell.extensions.weather woeid $WOEID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment