Created
August 29, 2011 03:10
-
-
Save marsam/1177704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 'Usando thetimenow.com' | |
print get_datetime2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment