Skip to content

Instantly share code, notes, and snippets.

@jonlabelle
Last active December 25, 2015 03:39
Show Gist options
  • Save jonlabelle/6911181 to your computer and use it in GitHub Desktop.
Save jonlabelle/6911181 to your computer and use it in GitHub Desktop.
Fetch atomic time for your current locale in Python.
#!/usr/bin/env python
import re
import urllib2
def fetch_data():
return str(urllib2.urlopen('http://time.is').read())
def find_patterns(pattern, text):
return re.findall(pattern, text)
def process_results():
patterns = map(
re.compile, [r'<div id="twd">(\d\d:\d\d:\d\d)', r'<span id="ampm"[^>]*>(.*?)</span>'])
data = fetch_data()
out = ''
for pattern in patterns:
out = out + ' ' + ''.join(find_patterns(pattern, data))
return out
if __name__ == '__main__':
result = process_results()
# ex: 07:36:48 PM
print(result.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment