-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Expand file tree
/
Copy pathantigravity.py
More file actions
49 lines (37 loc) · 1.69 KB
/
antigravity.py
File metadata and controls
49 lines (37 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Antigravity module - A humorous reference to xkcd comic #353.
This module contains a geohash function inspired by xkcd comic #426,
which provides a humorous take on geolocation hashing.
Upon import, this module automatically opens xkcd comic #353 in your web browser.
"""
import webbrowser
import hashlib
# Open the xkcd comic that inspired this module
webbrowser.open("https://xkcd.com/353/")
def geohash(latitude, longitude, datedow):
"""Compute geohash() using the Munroe algorithm.
This function implements a humorous geolocation hashing algorithm
inspired by xkcd comic #426. It takes geographic coordinates and a date,
then generates a "geohash" by combining the coordinates with values
derived from an MD5 hash of the date.
Args:
latitude (float): The latitude coordinate.
longitude (float): The longitude coordinate.
datedow (bytes): A date string in bytes format to use for hashing.
Returns:
None: This function prints the result instead of returning it.
Example:
>>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
37.857713 -122.544543
Note:
This is a humorous implementation and should not be used for
actual geolocation purposes. For real geohashing, consider using
a proper geohashing library.
References:
- xkcd comic #426: https://xkcd.com/426/
- xkcd comic #353: https://xkcd.com/353/
"""
# https://xkcd.com/426/
h = hashlib.md5(datedow, usedforsecurity=False).hexdigest()
p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])]
print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))