Twitter Updates with geolocation

Update your twitter with your current geolocation, from terminal
I was playing with a python wrapper around the Twitter API and made a simple class that would update twitter status with the geolocation derived from your IP address. The limitation begin proxies and a limited 70 chars status, yes there are few command like whereami but this is for the fun of it. When we travel here and there we can update our location with latitude and longitude, yes indeed even that can be made via a web browser, this for people who love there terminal more than anything.

The code is self explanatory with sensible comments where ever necessary, it uses urllib2 and python-twitter, which you must down from get python-twitter and install.

The below is the code that need to be edited, to indeed add the username and password of your twitter account.

#!/usr/bin/env python
# Twitt Geo-location
# -*- coding: utf-8 -*-
# Author Hemanth.HM
# Site :
# Licensed under GNU GPL Version 3

import twitter
import urllib2


class Geolocate:
    """Class Geolocate to get the current geo-location and also twitt the same"""
    def get_info(self):
        """Returns the current location"""
        """ Query URI's """
        pub_ip = urllib2.urlopen(myip).read()
        url= url%(pub_ip)
        location = urllib2.urlopen(url).read()
        location = location.splitlines()
        del location[-1] # Remove ip for security.
        return " ".join(location)

    def twit(self):
        """Updates twitter status with current location, limitation 70 chars"""
                status = raw_input("Type in your status [70 chars]: ")
                twit = twitter.Api(username=USERNAME, password=PASSWORD)
                twit.PostUpdate(status+" "+self.get_info())
        except Exception, why:
                print str(why)

def main():
        wai = Geolocate()

if __name__ == "__main__":

Example Location:
'Country: INDIA (IN) City: Bangalore Latitude: 12.9833 Longitude: 77.5833'
Get the code and do share your scripts in the comments below.

Share this