/jc-weather

Alfred 2 Workflow for getting weather forecasts

Primary LanguagePythonMIT LicenseMIT

Alfred 2 Workflow for showing weather forecasts

screenshot-weather

Download

This workflow lets you access weather forecasts from forecast.io and the Weather Underground. There are several setup commands, accessible as wset <command>, and a single weather command to display current conditions and a forecast.

The setup commands are:

  • days - set the number of forecast days to show
  • format - set the format for displaying timestamps
  • getkey - open the API key signup page for your current service
  • icons - choose an icon set
  • location <ZIP or city> - set your default location
  • service - set your preferred weather service, forecast.io or Weather Underground
  • units - set your preferred unit system

The first time you try to access the weather, you'll be asked to set your preferred service, currently either Weather Underground or Forecast.io. You'll also be asked to set an API key for your chosen service. If you don't already have a key you can use wset getkey to open the API signup page for the weather service. API keys from both Weather Underground and forecast.io are free.

Once you've set the service and API key, you'll also need to set a default location. This is done with the wset location command.

The weather command, with no argument, will show information for your default location. It can also be given a location, such as a ZIP code or city name. It (and the wset location command) uses the Weather Underground autocomplete API to find possible locations based on what you enter.

Data for each city you query is cached for 5 minutes to keep requests down to a reasonable level while you're playing around with the workflow. The free tier of Weather Underground API access is throttled to 10 requests per minute, and it's surprisingly easy to hit that limit (you know, when you're spastically querying city after city because using an Alfred workflow is just so cool).

###Sunrise and Sunset Using sun [location] to show sunrise and sunset time for the next few days.

screenshot-sun

Installation

The easiest way to install the workflow is to download the prepackaged workflow. Double-click on the downloaded file, or drag it into the Alfred Workflows window, and Alfred should install it.

I'm using weather as the main command, which is the same as the built-in weather web search in Alfred. The web search can be disabled in Features → Web Search if you don't want it showing up in your weather report. Alternatively, you can change the weather command to something else.

Requirements

The only requirements are:

  • Python 2.7+
  • requests
  • pytz

If you have Lion or Mountain Lion, the prepackaged workflow includes everything you need.

Credits

This script was originally based on David Ferguson's Weather workflow. My code base has diverged pretty far at this point, though, both in the source and in how it works.

The package includes a number of icon sets from the Weather Underground and from weathericonsets.com (I'm not up to drawing weather icons yet). Each set includes an info.json file that gives a short description and provides a source URL for the icon set.