WikiLeaks Cablegate Count v2

Since the official WikiLeaks page has changed, the previous script needs to be updated. Here it is:

import urllib, piksemel, re

wleaks = int(re.search(r"(d+) / [0-9,]+", piksemel.parseString(urllib.urlopen("http://www.wikileaks.ch/cablegate.html").read()).getTag("body").getTag("div").getTag("div").getTag("a").nextTag().getTag("p").toString()).groups()[0])

Please remember to install piksemel module.

WikiLeaks Cablegate Count

Today, I wrote a small script to get the count of released WikiLeaks cables. Actually, it’s extremely small. Just two lines of code.

import urllib, piksemel, re

wleaks = int(re.search(r"(d+) / [0-9,]+", piksemel.parseString(urllib.urlopen("http://cablegate.wikileaks.org/index.html").read()).getTag("body").getTag("div").getTag("div").getTag("a").getTag("p").toString()).groups()[0])

Generally, I don’t code like this. But I wanted to write it quick (5 minutes?) and keep it short. It uses piksemel to parse the page.

Enjoy!

Pardus at CeBIT 2010 Eurasia

This week had been an exhausting one. I was an exhibitor at Pardus at CeBIT 2010 Eurasia. I’ve talked about Pardus, Linux and open software for 4 days, all day long. Being there as a volunteer and working hard didn’t matter. WE HAD FUN!

While we’re giving visitors gifts (Pardus 2009.2 CD’s, posters, brochures and candies), they asked questions about Pardus. Such as: “Is this really free, but why?”, “Where do you get money from?”, “What does free mean?”, “Can I contribute Pardus?”, “Can I use it in my office?”, “How many people uses that?”, “How secure is it?”…

The crowd was enthusiastic about using Pardus. All we have to do is let them play with it a little. There was 10 computers for trying Pardus, and Pardus handled rest of it. Interfaces, effects, ease of use and (open source) games were good enough to attract them! They were just scared to try something different. We gave them enough courage to try Pardus, now we’re waiting for their feedback.

I will save my CeBIT badge forever and I’m too glad to met other volunteers from Özgürlükİçin.com in person, and they’re all awesome! I took a lot of photographs. Cannot wait until next event!

Show forecast using Yahoo! Weather

Note: This snippet uses piksemel module to parse XML files. If you don’t have it, read this article to install it.

First of all, you need the WOEID (Where on Earth Identification) of the city. In order to learn it, go to http://weather.yahoo.com and search for the city. You’ll find the WOEID at the end of the url of the page.

# for Istanbul, TR
woeid = 2344116

Use this id in Yahoo! Weather API url, for w parameter.

weatherUri = "http://weather.yahooapis.com/forecastrss?w=%d" % woeid

If you want the results to be in metric units, add u=c parameter into your query.

weatherUri = "http://weather.yahooapis.com/forecastrss?w=%d&u=c" % woeid

Using urllib, fetch the XML file:

import urllib

xml = urllib.urlopen(weatherUri).read()

We can parse this XML easily using piksemel:

import piksemel

temp = piksemel.parseString(xml).getTag('channel').getTag('item').getTag('yweather:condition').getAttribute('temp')

You can also view XML file and look for other resources such as: humidity, visibility, wind, etc.

How to install piksemel module

piksemel is a easy to use python XML parser, based on iksemel.

Not: If you’re using Pardus, piksemel is preinstalled on your system.

Not: If you’re using Windows, before you continue make sure you’ve already installed mingw32 to your system and its directory is included in PATH.

Steps for Linux users:

  • Download the package from http://cekirdek.pardus.org.tr/~bahadir/piksemel/piksemel-1.3.1.tar.gz and unpack it.
  • Run:
    python setup.py build
  • Run:
    python setup.py install

Steps for Windows users:

  • Download the package from http://cekirdek.pardus.org.tr/~bahadir/piksemel/piksemel-1.3.1.tar.gz and unpack it.
  • In piksemel-1.3.1 directory, run:
    setup.py bdist_wininst build --compiler=mingw32
  • Run the installer file under the piksemel-1.3.1/dist directory.

Hello World

I decided to activate my blog again, with brand-new posts!

My posts will be about php and python programming languages, Linux and open source software. I’m planning to write in English, but some posts might be in Turkish as well. Since I’m just not that good at English, excuse me for my probable mistakes and feel free to correct them.

Tutorials, snippets, reviews and more… It’s gonna be fun!

Stay connected.