Skip to content

Commit 4a662c0

Browse files
author
Karan Goel
committed
Atomic time done
1 parent 2804712 commit 4a662c0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Web/time.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Get Atomic Time from Internet Clock - This program will get
3+
the true atomic time from an atomic time clock on the Internet.
4+
Use any one of the atomic clocks returned by a simple Google search.
5+
"""
6+
7+
import re
8+
from urllib2 import urlopen
9+
10+
11+
def main():
12+
url = 'http://time.is/just'
13+
content = urlopen(url).read()
14+
pattern = re.compile('<div id="twd">(.*)<span id="ampm" style="font-size:21px;line-height:21px">(AM|PM)</span></div>')
15+
16+
find_match = re.search(pattern, content)
17+
18+
location_pat = re.compile('<h1 id="pL" class="w90 tr"><a href="/facts/\w+">(.*)</a></h1>')
19+
location_match = re.search(location_pat, content)
20+
21+
print 'The time in %s is %s %s' % \
22+
(location_match.group(1), find_match.group(1), find_match.group(2))
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)