Last active
December 25, 2015 03:39
Fetch atomic time for your current locale in Python.
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 | |
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