Skip to content

Instantly share code, notes, and snippets.

@marsam
Created August 29, 2011 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marsam/1177704 to your computer and use it in GitHub Desktop.
Save marsam/1177704 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import urllib
import urllib2
def get_datetime():
"""Usa el servicio json-time.appspot.com para obtener el tiempo."""
query = {'tz': 'America/Lima'}
query_encoded = urllib.urlencode(query)
# url = 'http://json-time.appspot.com/time.json'
try:
j = urllib.urlopen('http://json-time.appspot.com/time.json?%s'%(query_encoded)).read()
jtime = json.loads(j)
return jtime['datetime']
except Exception, e:
sys.stderr('No se pudo conseguir el datetime :-( : %s'%e)
def get_datetime2():
"""Usa el servicio thetimenow.com para obtener el tiempo."""
query = {'tz':'America/Lima'}
query_encoded = urllib.urlencode(query)
# url = 'http://www.thetimenow.com/sync.php'
try:
j = urllib.urlopen('http://www.thetimenow.com/sync.php?', query_encoded).read()
jtime = json.loads(j)
return jtime['America/Lima']
except Exception, e:
sys.stderr('No se pudo conseguir el datetime :-( : %s'%e)
if __name__ == '__main__':
print 'Usando json-time.appspot.com'
print get_datetime()
print
print 'Usando thetimenow.com'
print get_datetime2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment