2023-04-30 14:08:32 +03:00
|
|
|
from pelican import signals
|
|
|
|
|
import geohash_tools as gh
|
|
|
|
|
|
2023-05-03 00:21:33 +03:00
|
|
|
hashes = []
|
|
|
|
|
|
2023-04-30 14:08:32 +03:00
|
|
|
def generate_geohash(generator):
|
|
|
|
|
for article in generator.articles:
|
|
|
|
|
if "location" in article.metadata:
|
|
|
|
|
lat, lon = [float(i) for i in article.metadata['location'].replace(' ', '').split(',')]
|
2023-05-01 21:58:23 +03:00
|
|
|
article.metadata['lat'] = lat
|
|
|
|
|
article.metadata['lon'] = lon
|
2023-04-30 14:08:32 +03:00
|
|
|
article.metadata['geohash'] = gh.encode(lat, lon, 11)
|
2023-05-03 00:21:33 +03:00
|
|
|
if article.metadata['geohash'] not in hashes:
|
|
|
|
|
article.slug = gh.encode(lat, lon, 11)
|
|
|
|
|
hashes.append(article.metadata['geohash'])
|
2023-04-30 14:08:32 +03:00
|
|
|
|
|
|
|
|
def register():
|
|
|
|
|
signals.article_generator_finalized.connect(generate_geohash)
|