Using Google Geocoding API in Python

Started work on a wrapper for the Google Geocoding API, called pygeocoding. Check out the Github page for the code and usage.

The intent is to provide a Pythonistic interface in building your Google Maps such as building a Google Map in Django with locations stored in your models. As noted on the API page:

Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.

Some example usage:

import pygeocoding

# Let's find CERN
pygeocoding.LookUp(address="CERN CH-1211 Genève 23 Switzerland")
{u'status': u'OK', u'results': [{u'geometry': {u'location_type': u'APPROXIMATE', # ... truncated output

# We can also search backwards - let's pipe in the lat/long of the liberty bell (approximately)
# - we'll just see what the first result is
r = pygeocoding.LookUp(latlng="39.9518819802915,-75.1476150197085")

# now we can pipe these results to our mapping functions

Post to Facebook with Python

Let’s take a quick look at a great tool to post to Facebook from Python called fbconsole. It’s fairly self explanatory, so I won’t bother going into much textual detail here. I’ll take you through some of the basic features and highlight as we go. In the following code snippet, we will post some data to our personal status feed, similar to how we push from KindleQuotes to Facebook when a user would like to share an item.

import fbconsole as F

# If you have an APP ID from Facebook, you can add that here.
# Otherwise, you will be posting as fbconsole.

# Set some authentication parameters
# Here we will set the ability to publish to a stream
F.AUTH_SCOPE = ['publish_stream']

# Now we will login and get our OAuth token.

# After successful login, we can add our status update.
# Let's assume we have some neat data we want to push to the stream.
# We'll post our world_changing_data to our personal feed'/me/feed', {'message': world_changing_data})

# Want to logout and wipe your OAuth token?

We just completed a very simple data push to our Facebook status feed from within our python program. There is a lot more functionality to check out once you have the basic setup working in your program.

Stumpy Version 1.5 is Now Available!

Stumpy Version 1.5 is now out and ready for testing.
Should be functional, but please submit any issues you might find to the issues page.

Changes include (from commits):

  • Removed hardcoded domains from JS. We now pipe in through the stumpy_domain var by setting a global JS var ‘DOMAIN’ in the index and then reference that JS var in our scripts. You will no longer need to set your domain as hard coded into javascript code.
  • Updated to use get submission of new URLs for shortening. This should work, but needs to be tested on the production version to make sure WSGI and such are working okay without the earlier hack that was implemented.

Checking your SSH key Fingerprint

As many of you probably are already well aware, Github recently was made aware of a mass-assignment vulnerability (1). If you aren’t caught up, you can find the info here on the Github blog (2, 3).

This afternoon, Github sent out an email to users that they had disabled all SSH keys for a users’ accounts and they would remain suspended until validated. You can validate your keys by visiting the SSH keys section under your account settings where you will then be able to reject or validate each of your stored keys. These are listed by machine ID and key fingerprint.

But how do you know the fingerprint of your SSH key to ensure it is the correct one for each machine ID? Simply SSH into each machine and run the following, replacing the location of the key to match where you have yours stored:

ssh-keygen -lf ~/.ssh/

Monty Hall Sneak Peak

Coming Soon: Monty Hall game player in Python.

For now, here is a little teaser:

The 10 billion iteration answer:
Ran 10000000000 iterations in 104833.082781s {'wins': 3333340564L, 'losses': 6666659436L}

The code is hosted, of course, on GitHub and can be found here:

As soon as I get the rest of it written up I’ll be posting everything here along with a little code walk-through including a very basic example of Python decorators as well as general object-oriented approaches.

Bash Snippet for Git Users

Keeping track of what branch you are using while in a git repository can be a bit of a pain. Adding the following code to your ~/.bashrc file can make it a bit easier since it will prepend your prompt with the current branch.

function parse_git_branch {
    GIT_BRANCH=$(git branch --no-color 2> /dev/null | awk '{if ($1 == "*") { printf "(%s) ",$2}}')
    PS1="$GIT_BRANCH\u@\h:\w\$ "

Here it is working:
[email protected]:~$ source /etc/bash.bashrc 
[email protected]:~$ cd programming/bits
(master) [email protected]:~/programming/bits$ 

Stumpy Updated – v1.4.3

The Mutaku URL shortener, Stumpy, has now been updated to version 1.4.3.

You can find out more about Stumpy by clicking the first link in this post to read the initial write up on Mutaku, or you can go to the project page on Github.

Stumpy main page

This release includes a few small bug fixes as well as incorporating a new feature that, for logged in users, shows all of their submitted URLS at the bottom of the main page. Previously, this was only viewable by going through the admin interface. If you are not logged in, you will see the traditional view with the 5 most recent and 5 most visited URLs.

You get get the newest release at the Github page here: v1.4.3