Created
January 8, 2012 20:52
-
-
Save kshwetabh/1579644 to your computer and use it in GitHub Desktop.
Change Wallpaper based on current weather condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pywapi | |
import string | |
''' | |
CurrentWeatherWall | |
Set you desektop wallpaper as per the current weather condition | |
OS: Ubuntu {I have tested on Ubuntu 11.10} | |
See the import statements for Python module dependencies | |
Replace/substiture the following: | |
zipcode: zipcode of your current location | |
weather_conditions: images of your choice in this dictionary | |
[Note: The code assumes all images should be in the current directory as this py file is in] | |
''' | |
zipcode = "30005"; | |
''' | |
Weather conditions list taken from : http://dennisdel.com/content/conditions.xml | |
Google Weather API Conditions. Compiled by Dennis Delimarsky | |
<!-- Last updated: March 12, 2010 --> | |
Dictionary of all weather conditions from Google Weather API with the corresponding wallpaper | |
''' | |
weather_conditions = {\ | |
'partly sunny':'partlysunny.png',\ | |
'scattered thunderstorms':'scatteredthunderstorms.png',\ | |
'showers':'showes.png',\ | |
'scattered showers':'scatteredshowers.png',\ | |
'rain and snow':'rainandsnow.png',\ | |
'overcast':'overcast.png',\ | |
'light snow':'lightsnow.png',\ | |
'freezing drizzle':'freezingdrizzle.png',\ | |
'chance of rain':'chanceofrain.png',\ | |
'sunny':'sunny.png',\ | |
'clear':'clear.png',\ | |
'mostly sunny':'mostlysunny.png',\ | |
'partly cloudy':'partlycloudy.png',\ | |
'mostly cloudy':'mostlycloudy.png',\ | |
'chance of storm':'chanceofstorm.png',\ | |
'rain':'rain.jpg',\ | |
'chance of snow':'chanceofsnow.png',\ | |
'cloudy':'cloudy.png',\ | |
'mist':'mist.png',\ | |
'storm':'storm.png',\ | |
'thunderstorm':'thunderstorm.png',\ | |
'chance of tstorm':'chanceoftstorm.png',\ | |
'sleet':'sleet.png',\ | |
'snow':'snow.png',\ | |
'icy':'icy.png',\ | |
'dust':'dust.png',\ | |
'fog':'fog.jpg',\ | |
'smoke':'smoke.png',\ | |
'haze':'haze.png',\ | |
'flurries':'flurries.png',\ | |
'light rain':'lightrain.jpg',\ | |
'snow showers':'snowshowers.png',\ | |
'ice/snow':'icesnow.png',\ | |
'windy':'windy.png',\ | |
'scattered snow showers':'scatteredsnowshowers.png' | |
} | |
wallpaper = ''; | |
google_result = pywapi.get_weather_from_google(zipcode) | |
for condition, wall in weather_conditions.iteritems(): | |
print condition +":" + wall | |
if string.lower(condition) == string.lower(google_result['current_conditions']['condition']): | |
wallpaper = wall | |
break | |
#Not really required. These print statements are here only for debugging | |
print "Google says: It is " + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + "C now in "+ google_result['forecast_information']['city']+".\n\n" | |
print "wallpaper is: " + wallpaper | |
os.system("gsettings set org.gnome.desktop.background picture-uri file://" + os.getcwd() + "//" + wallpaper) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment