Skip to main content

Posts

Showing posts from October, 2012

Display dynamic content in Google Earth using KML

Keyhole Markup Language (KML) is a xml standard which can be used to define what and how to present geographic data in Google Earth and Google Maps. Useful examples to start can be browsed via https://developers.google.com/kml/documentation/kml_tut . I have to display KML data in googleearth. And the KML file has to be loaded dynamically and the updates in the kml file should be shown in the googleearth on the fly. For this we have to Create a Network Link. Goto Add -> Network Link Then specify the details as shown in the figure. To specify the frequency of updating the data, go to Refresh tab. The code for dynamicKML.kml is as follows: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.1"> <document> <networklink> <link> <href>junk.kml</href> <refreshmode>onInterval</refreshMode> <refreshinterval&g

python code for querying own IP address

The  socket.gethostname() function is supposed to give the IP address of the machine but it may not give the real IP address but gives 127.0.0.1 . Even it is said that removing 127.0.0.1 from the /etc/hosts file (in ubuntu) can give the real IP but it could not help in my case. import socket nodeName = socket.gethostname() info = socket.getaddrinfo(nodeName, None, 0, socket.SOCK_STREAM) print [x[4][0] for x in info]   # prints 127.0.0.1 I came through another way which can print the real IP as well: import commands NodeIPS = commands.getoutput("/sbin/ifconfig | grep -i \"inet\" | grep -iv \"inet6\" | " +                          "awk {'print $2'} | sed -ne 's/addr\:/ /p'") print NodeIPS  # prints 127.0.0.1 and realIP(eg. 202.145.12.22) Note: code worked for ubuntu 12.04 and python 2.7 Sometimes its handy to have the IP address as list items. The following code does the work. import os listIPs=[] f=os.pope

Open file with unlisted application in ubuntu 12.04

In ubuntu 12.04, While browsing files in nautilus, if we want to open file with unlisted applications, for e.g. open a file with idle(but idle is not listed in the list of open with ). Enter the following command in the terminal: gksudo gedit /usr/share/applications/idle.desktop Then remove the line: Exec=/usr/bin/idle -n Replace it with: Exec=idle %U Now we can see idle listed in the list of open with applications. To set it as default application to open a file. Go to the file properites, select idle and click set as default.