Using Google Latitude to print current location - UPDATED

May 23, 2013
Here goes the updated version of my old script.

Biggest change is Google Maps v3 don't require login anymore and there's no need for the geopy module. Feel free to add exceptions and other stuff.


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# latitude.py
#
# Copyright (c) 2013 Ruslan Valiyev
# ruslan@valiyev.com
#
import simplejson as json
import time
import urllib2

#
# Get your Latitude user id
# Go to: http://www.google.com/latitude/apps/badge
# Look for the id in the badge html code eg.
# <iframe src="http://latitude.google.com/latitude/apps/badge/api?user=<YOUR_ID_WILL_BE_HERE>
#
GOOGLE_LATITUDE_KEY = '<YOUR_ID_WILL_BE_HERE>'
GOOGLE_LATITUDE_URL = 'http://www.google.com/latitude/apps/badge/api?user=%s&type=json'
GOOGLE_MAPS_URL = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%s&sensor=false'

class GLatitude:
  def __init__(self, uid):
    # http://www.google.com/latitude/apps/badge/api?user=<YOUR_ID_WILL_BE_HERE>&type=json
    self.glatitude = json.load(
      urllib2.urlopen(GOOGLE_LATITUDE_URL % uid)
    )

  def coords(self):
    return self.glatitude['features'][0]['geometry']['coordinates']

  def timestamp(self):
    epoch = self.glatitude['features'][0]['properties']['timeStamp']
    human = time.strftime('%d %b %Y %H:%M', time.localtime(epoch))
    return human

class Gmaps:
  def __init__(self, i):
    self.gmaps = json.load(                                                                                                                                            
      urllib2.urlopen(GOOGLE_MAPS_URL % i)
    )
  def geoinfo(self):
    return self.gmaps['results'][0]['formatted_address']


def main():
  gl = GLatitude(GOOGLE_LATITUDE_KEY)
  location = gl.coords()[::-1]
  last_location_coords = ','.join(str(i) for i in location)
  last_time = gl.timestamp()
  gm = Gmaps(last_location_coords)

  return last_time, last_location_coords, gm.geoinfo()

if __name__ == '__main__':
  print main()
Sample output:

>>> import latitude
>>> latitude.main()
('23 May 2013 10:19', '46.2384963,6.1222947', 'Chemin du Pavillon 2, 1218 Grand-Saconnex, Switzerland')

procstat-json

December 22, 2012
I just uploaded a small app on github that reads various system statistics from the /proc filesystem plus runs a Tornado server, providing JSON-like data for realtime monitoring. Check it out.

Here's a screenshot, demonstrating Google Chart Tools.

How to configure Time Machine disk size on Synology NAS

November 11, 2012
Here's how to limit the backup disk size when it's stored on a Synology NAS. In my case I set it to 1TB.

Become root or run with sudo:


imac:~ root# hdiutil resize -size 1000G -shrinkonly /Volumes/Time\ Machine/imac.sparsebundle

SNMP and Synology MIB

August 31, 2012
Thanks to Synology for finally making their MIB public. Although, you're gonna have to upgrade to DSM 4.1 before taking advantage of it.


synonas> ls -l /usr/syno/share/snmp/mibs/SYNOLOGY-*
-rw-r--r--    1 root     root          2513 Aug 30 11:17 /usr/syno/share/snmp/mibs/SYNOLOGY-DISK-MIB.txt
-rw-r--r--    1 root     root          2000 Aug 30 11:17 /usr/syno/share/snmp/mibs/SYNOLOGY-RAID-MIB.txt
-rw-r--r--    1 root     root          1912 Aug 30 11:17 /usr/syno/share/snmp/mibs/SYNOLOGY-SYSTEM-MIB.txt


synonas> snmpwalk -c public -v2c localhost synoSystem
SYNOLOGY-SYSTEM-MIB::SystemStatus.0 = INTEGER: Normal(1)
SYNOLOGY-SYSTEM-MIB::Temperature.0 = INTEGER: 46
SYNOLOGY-SYSTEM-MIB::PowerStatus.0 = INTEGER: Normal(1)
SYNOLOGY-SYSTEM-MIB::SystemFanStatus.0 = INTEGER: Normal(1)
SYNOLOGY-SYSTEM-MIB::CPUFanStatus.0 = INTEGER: Normal(1)


synonas> snmpwalk -c public -v2c localhost synoDisk
SYNOLOGY-DISK-MIB::DiskID.0 = STRING: "Disk 1"
SYNOLOGY-DISK-MIB::DiskID.1 = STRING: "Disk 2"
SYNOLOGY-DISK-MIB::DiskID.2 = STRING: "Disk 3"
SYNOLOGY-DISK-MIB::DiskID.3 = STRING: "Disk 4"
SYNOLOGY-DISK-MIB::DiskID.4 = STRING: "Disk 5"
SYNOLOGY-DISK-MIB::DiskModel.0 = STRING: "WD20EARS-00MVWB0"
SYNOLOGY-DISK-MIB::DiskModel.1 = STRING: "WD20EARS-00J99B0"
SYNOLOGY-DISK-MIB::DiskModel.2 = STRING: "WD20EARS-00MVWB0"
SYNOLOGY-DISK-MIB::DiskModel.3 = STRING: "WD20EARS-00MVWB0"
SYNOLOGY-DISK-MIB::DiskModel.4 = STRING: "WD20EARS-00MVWB0"
SYNOLOGY-DISK-MIB::DiskType.0 = STRING: "SATA"
SYNOLOGY-DISK-MIB::DiskType.1 = STRING: "SATA"
SYNOLOGY-DISK-MIB::DiskType.2 = STRING: "SATA"
SYNOLOGY-DISK-MIB::DiskType.3 = STRING: "SATA"
SYNOLOGY-DISK-MIB::DiskType.4 = STRING: "SATA"
SYNOLOGY-DISK-MIB::DiskStatus.0 = INTEGER: Normal(1)
SYNOLOGY-DISK-MIB::DiskStatus.1 = INTEGER: Normal(1)
SYNOLOGY-DISK-MIB::DiskStatus.2 = INTEGER: Normal(1)
SYNOLOGY-DISK-MIB::DiskStatus.3 = INTEGER: Normal(1)
SYNOLOGY-DISK-MIB::DiskStatus.4 = INTEGER: Normal(1)
SYNOLOGY-DISK-MIB::DiskTemperature.0 = INTEGER: 42
SYNOLOGY-DISK-MIB::DiskTemperature.1 = INTEGER: 46
SYNOLOGY-DISK-MIB::DiskTemperature.2 = INTEGER: 45
SYNOLOGY-DISK-MIB::DiskTemperature.3 = INTEGER: 46
SYNOLOGY-DISK-MIB::DiskTemperature.4 = INTEGER: 44


synonas> snmpwalk -c public -v2c localhost synoRaid
SYNOLOGY-RAID-MIB::RaidName.0 = STRING: "Volume 1"
SYNOLOGY-RAID-MIB::RaidStatus.0 = INTEGER: Normal(1)

Caching IPMI data

August 10, 2012
I just discovered there's a dump-to-cache option when executing ipmitool.
It sure speeds things up by a factor of ~10 in my case.

Dump sdr to a file called ipmi.cache


# time ipmitool -H 192.168.10.181 -U someuser -P somepass sdr dump ipmi.cache
Dumping Sensor Data Repository to 'ipmi.cache'

real    0m5.422s
user    0m0.004s
sys     0m0.016s

Without cache


# time ipmitool -H 192.168.10.181 -U someuser -P somepass sdr type Temp
/PS0/TEMP_FAULT  | 27h | lnc | 10.0 | 0 unspecified
/PS1/TEMP_FAULT  | 36h | lnc | 10.1 | 0 unspecified
...

real    0m7.476s
user    0m0.007s
sys     0m0.017s

With cache


~# time ipmitool -S ipmi.cache -H 192.168.10.181 -U someuser -P somepass sdr type Temp
/PS0/TEMP_FAULT  | 27h | lnc | 10.0 | 0 unspecified
/PS1/TEMP_FAULT  | 36h | lnc | 10.1 | 0 unspecified
...

real    0m0.763s
user    0m0.001s
sys     0m0.001s