blob: 6dc520733577af68cd7926105204baf807251a39 [file] [log] [blame]
Benjamin Peterson206e3072008-10-19 14:07:49 +00001
2import webbrowser
Raymond Hettingerb1614a72009-06-03 17:21:17 +00003import hashlib
Benjamin Peterson206e3072008-10-19 14:07:49 +00004
Christian Heimesa4961e52016-09-16 13:48:10 +02005webbrowser.open("https://xkcd.com/353/")
Raymond Hettingerb1614a72009-06-03 17:21:17 +00006
7def geohash(latitude, longitude, datedow):
8 '''Compute geohash() using the Munroe algorithm.
9
10 >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
11 37.857713 -122.544543
12
13 '''
83df50e2018-09-14 13:45:00 +080014 # https://xkcd.com/426/
Miro Hrončok4c0a31f2020-04-14 21:49:11 +020015 h = hashlib.md5(datedow, usedforsecurity=False).hexdigest()
Raymond Hettingerb1614a72009-06-03 17:21:17 +000016 p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])]
17 print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))