Command Line Tools: weather, todo, wget, tweet, and solve

Now that Cygwin is just a keyboard shortcut away, it’s time to explore a little of what it can do.

Download files: wget

This is a tool built into Cygwin that makes it easy to download files without needing a web browser. Simply type wget [a url] to download a single file.

But wget has a lot more features than that. For example, if you want to download a lot of files, you can save a list of URLs to a text file, putting each URL on its own line. Then, open cygwin and type wget -i listoffiles.txt and wget will download each file, one after another.

If you’re looking for more interesting ways to use wget, you’ll probably find this Lifehacker post relevant.

Get weather forecasts: weather

When we’re finished, you will be able to type the word weather into the console and get back a list of current local weather conditions and a local weather forecast (example). We’ll be using a shell script written by Jeremy Stanley to make this happen.

NOTE: Since this script pulls its forecast information from the U.S. National Weather Service, forecasts are only available for US territories. However, international readers can still get their current weather conditions since that data is provided by local airports.

  1. Download the latest version of the script.
  2. Open it by typing tar -xvf [filename] and change to the new folder by typing cd [new folder name].
  3. optional If you want to try the script out, typing in ./weather ATL will return the current conditions at the Atlanta airport.
  4. Now, to get your local conditions/forecast, you’ll need to edit the weatherrc file in your favorite text editor. Add the following lines to the top of the file (after the copyright notice).

    [default]
    Forecast = True
    City = Greenville Spartanburg
    St = SC
    ID = KGSP

    That’s the configuration to get my local forecast. To get yours, we’ll need to change the city, st, and ID variables to your location.

    To get a forecast, you’ll need to put in a city that the National Weather Service provides information for. Go here and select your state to find what cities are available. If you don’t want a forecast, just delete the Forecast = True line.

    To get current conditions, you’ll need to provide the METAR id for your nearest airport. Go to this map and click on the city closest to you. Under the map will be the METAR id for that airport.

    Save the weatherrc file and type ./weather into cygwin. It should give you a local forecast with current weather conditions.

  5. optional Let’s make it so that you can get your weather from anywhere in the file system and so that you don’t have to type that annoying ./ beforehand. We’re gonna have to move some files around.

    If it doesn’t already exist in your home folder, make a folder called bin (mkdir bin). Move just the weather file to that folder. Make sure it’s executable by typing chmod +x weather.

    Next, type python -c "import sys ; print sys.path" to find out where to put weather.py and weather.pyc. I put mine in /usr/lib/python2.5

    Then, move weather.1 and weatherrc.5 to /usr/share/local/man/man1, which is where cygwin stores manual files. (Once you do this, you can type man weather or man weatherrc to find out more about how to use this weather script.)

    Finally, move weatherrc to your home folder. I recommend renaming it .weatherrc, which will make it invisible to the ls command.

    Now, you’ll need to make sure cygwin knows to look in the bin folder for the weather script. Open the .bash_profile file in your home folder and make sure these lines are included and not commented out:

    if [ -d "${HOME}/bin" ] ; then
    PATH=${HOME}/bin:${PATH}
    fi

    Once you’ve done all that, type weather into cygwin, and it should give you the forecast and current conditions no matter where you are in the file system.

Manage a todo list: todo

Gina Tripani from Lifehacker has started an open source command line todo list manager. Once installed you can type things like todo add "Write blog post" to add an item to your todo list, todo ls to get a list of things to do, and todo do 1 to cross off the first thing on the list, and a lot more.

You can find plenty more about the script and how to install it at the link above.

Update twitter: tweet

This python script will let you easily send messages to Twitter from the command line. Simply copy and paste this code to a text file and save it as tweet.py (ideally in the bin directory you made above). To make it even more convenient, comment out or delete these lines:

user = raw_input(‘Username: ‘)
password = raw_input(‘Password: ‘)

and replace them with:

user = “your twitter user name”
password = “your twitter password”

Then open the .bash_profile file again and add this line to the bottom of the file:

alias tweet=’tweet.py’

Now you can type tweet "Message to send to twitter" to send tweets from the command line.

Solve math problems: solve

This one is easy: simply add the following lines to the end of your .bash_profile file:

function solve () {
awk “BEGIN { print $* ; }”
}

Now you can type solve "2*(3+4)" and it will return 14.

Hope you all find some of these tools useful! If you have any that you want to share, feel free to leave a comment.

Posted on
May 8, 2009 10:58 pm
 
 

Leave a Reply

Name and Mail fields are required. Emails will not be published.