Python Challenge Level 13

@10 Oct 2012 20:23 Tags: python pythonchallenge

import xmlrpclib
print server.system.listMethods()
- Comments: 0

Python Challenge Level 12

@10 Oct 2012 20:21 Tags: python pythonchallenge

[open("12_f%d.png" %i, "wb").write(info[i::5]) for i in range(5)]
print 'end'
- Comments: 0

Fetch weather information from BBC using Beautifulsoup

@09 Oct 2012 16:09 Tags:

Thanks to the help of Beautiful Soup.

Beautiful Soup is a Python library designed for quick turnaround projects like screen-scraping.

It is very easy to use and speed is acceptable (out of my concern).

I want to get the weather information from BBC website ( The website content is huge, at least for me. But that doesn't really matter. With the help of Beautiful Soup, I don't have to know the exact structure of the website.

First I need to import the urllib2 and BeautifullSoup library, also the pprint for output.

import urllib2
from bs4 import BeautifulSoup
import pprint

Download the whole website content from BBC and construct a soup object.
htmlData =

The number 2655984 stands for Belfast. When you select a different city in the BBC website (, the city number will show up in the browser address bar. 'day=0' means today and 'day=1' means tomorrow, etc..

All the weather information is in a html table, from the source of the website we can see

<table tabindex="0" class="weather moving-window three-hourly-0 one-hourly-12" 
    summary="Each column contains hourly forecast details for weather conditions, temperature, wind speed, wind direction, humidity, visibility and pressure.">

But we do not need so much information to find this table, in fact only one word 'weather' will do.

Other information like hours, temperatures and wind speeds can be find the table in the almost same way.

hours=[str(stime.span.string) for stime in table.find_all("th",class_="value")]
temperatures=[str(tem.contents[0]) for tem in table.find_all("span",class_="units-value temperature-value temperature-value-unit-c")]
windspeeds=[str(speed.contents[0]) for speed in table.find_all("span",class_="units-value windspeed-value windspeed-value-unit-kph")]

For the wind directions and weather types, code is a little different, because they are stored in table cells and sometimes the cell is empty, so I use try and catch to get values.
Of course there are better ways to do this.

for direction in table.find("tr",class_="wind-direction").find_all("td"):
for weathertype in table.find("tr",class_="weather-type").find_all("td"):

Finally put all the data on the output.
Here is all the code.
- Comments: 0

Thunderbird and addons

@09 Oct 2012 11:31 Tags: email

Thunderbird is the best email client on Windows and Linux (I have no Mac). With so many addons, it can be changed to anyway you like.

Download Thunderbird from its website website


  • easy to start: it has an email account setup wizard when you add new accounts, which means you do not have to add the server information manually. It is all done in a while.
  • Address book: store all your contacts in one place, and by the help of Zindus, it can be synced with Gmail contacts as well.
  • Calendar: using Lightning addon, thunderbird can have a calendar and what is more, with provider for google calendar, it can be synced with Google Calendar as well.
  • Manage multi accounts in one place: for those who have multi email accounts, you do not have to log in several times to check for new emails. And emails can be moved from one account to another in thunderbird— great for emails that have limited storage and have to be cleaned time to time.

Of course, if you have only one email and that is Gmail or, stay online then, it is better. - Comments: 0

除非特别注明,本页内容采用以下授权方式: Creative Commons Attribution-ShareAlike 3.0 License