Tag Archives: firefox

Python GeoIP (python-geoip) cities tutorial

Using geolocation is something that people are doing a lot lately.  You may have noticed twitter.com in FireFox showing a little bar at the top asking if it’s alright to share your location. This is so that when you tweet you can have your location show up there. That way you can keep track of where you tweet from.  There are many uses for this kind of information and these days there’s a lot of free things out there to help you get started with your geolocation project.

Installing GeoIP

Requirements/Dependancies:

  • Python 2.4+
  • python-geoip
  • libc6
  • libgeoip1

More on dependencies here http://ns2.canonical.com/es/karmic/python-geoip. But don’t worry about these since most of them get installed by the package anyway.

A couple of basic principles before we get started.

  1. Geolocation is gathered from an IP address.
  2. There has to be a database that connects the IP address to a geographical location

I’m going to be using Python here because frankly it’s powerful, easy and has awesome libraries for geolocation. Which brings me to the GeoIP library! I’m using Ubuntu 9.10 so most of these libraries will just take an apt-get to install.

Then you can install python-geoip with

sudo apt-get install python-geoip

Or you can get the source from http://geolite.maxmind.com/download/geoip/api/python/

Now that you have this installed you can  test it with the following code put in the python terminal.

>>> import GeoIP
>>> gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
>>> print gi.country_code_by_addr("203.195.93.0")

I got that from MaxMind’s tutorial http://www.maxmind.com/app/python. At this point you have the ability to track IPs down to the country level. What you probably really want is to go down to the city level.

Geolocation – Cities

If you call some of the other functions on the GeoIP class like record_by_addr() you’lld get an error like this

“Invalid database type GeoIP Country Edition, expected GeoIP City Edition, Rev 1″

Read more »

Bing.com blunder: Page 21 goes blank (FireFox)

Bing.com blanks out at page 21-22 of search results in FireFox.

Take a simple search in bing.com

http://www.bing.com/search?q=ford

This will give you page saying there are 160,000,000 results and you’re being shown 1-20 of them. That’s all fine and dandy but let’s say I want to just flip through the pages a little and see what’s new with Ford.

When you click on the pagination below the URL’s that your going to look something like this…

Page 2: http://www.bing.com/search?q=ford&first=6&FORM=PERE

Page 3: http://www.bing.com/search?q=ford&first=16&FORM=PERE1

Page 4: http://www.bing.com/search?q=ford&first=26&FORM=PERE2

Page 5: http://www.bing.com/search?q=ford&first=36&FORM=PERE3

You’ll notice a couple things changing in these urls.  The first should be the “first” GET variable in the URL which appears to be some kind of page offset for the results.

The next is that FORM=PERE business which I’m not sure exactly what it does and it didn’t seem to matter if I removed it from the URL anyway.

The key thing I found was that if you click through the pages until you get to around page 21 or 22 the screen goes completely blank and the magic variable value is changing “?first” to a value that’s greater than or equal to 200.  This seems to only be an issue in Firefox as far as I can tell.

I checked the headers with this and there doesn’t seem to be any significant differences.

$ curl -I http://www.bing.com/search?q=ford&first=16&FORM=PERE4

$ curl -I http://www.bing.com/search?q=ford&first=206&FORM=PERE4

Comment if you have any ideas?

Search Newegg with Ubiquity!

This is really quite lame but it’s early in the morning and I have completed my goal!

I made a Ubiquity command that searches newegg for me! Yes! That is correct! *streamers, confetti and hats*

Read more »

Unjustifiable Internet Explorer 7,8 and probably 9 as well

I think we all know that Microsofts Internet Explorer has been a failure for…quite some time (Sorry Microsoft, just fix it already).  Internet Explorer 7 and 8 have made huge advances over version 6, however, there are still many flaws and I ran into an obscure one the other day.

Read more »