summaryrefslogtreecommitdiff
path: root/regenerate_index_html.py
diff options
context:
space:
mode:
authorHoward Butler <howard@hobu.co>2019-12-26 04:47:14 -0600
committerEven Rouault <even.rouault@spatialys.com>2019-12-26 11:47:14 +0100
commitda360d32233f361a231b17c3252d660ca45864b2 (patch)
treee94b5e741ab85c20a20bce8cefe3c50b6fe232c1 /regenerate_index_html.py
parenta243afcacad83ff7efa0ee09057fa45a60b6ca40 (diff)
downloadPROJ-data-da360d32233f361a231b17c3252d660ca45864b2.tar.gz
PROJ-data-da360d32233f361a231b17c3252d660ca45864b2.zip
update cdn.proj.org landing page with links to agencies (#3)
Diffstat (limited to 'regenerate_index_html.py')
-rw-r--r--regenerate_index_html.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/regenerate_index_html.py b/regenerate_index_html.py
index 340f5a0..7daa639 100644
--- a/regenerate_index_html.py
+++ b/regenerate_index_html.py
@@ -1,7 +1,14 @@
from osgeo import gdal
-import datetime
import glob
import os
+import json
+import subprocess
+
+agency_list = json.loads(open('AGENCY.json','rt').read())
+agencies = {}
+for item in agency_list:
+ agencies[item['id']] = item
+
dirnames = []
links = []
@@ -24,7 +31,16 @@ for dirname in sorted(dirnames):
readme_filename = f
else:
filenames.append(f)
- links.append('</ul><ul>')
+
+ title = '%s' % (dirname)
+ try:
+ agency = agencies[dirname]
+ title = '<a href="%s">%s</a>' % (agency['url'].replace('&', "&amp;"), agency['agency'])
+ except KeyError:
+
+ pass
+
+ links.append('</ul><hr><h3>%s</h3><ul>' % title )
for f in [readme_filename] + sorted(filenames):
assert f not in set_files
@@ -50,12 +66,13 @@ for dirname in sorted(dirnames):
if f.startswith('README'):
last_modified = ''
else:
- last_modified = '. Last modified: ' + datetime.datetime.utcfromtimestamp(os.stat(full_filename).st_mtime).strftime("%Y/%m/%d")
+ p = subprocess.run(['git','log','-1','--pretty=format:%cd','--date=short',full_filename], check=True, stdout=subprocess.PIPE)
+ last_modified = '. Last modified: ' + p.stdout.decode('ascii')
links.append('<li><a href="%s">%s</a>%s%s%s</li>' % (f, f, desc, size_str, last_modified))
total_size_str = '%d MB' % (total_size // (1024 * 1024))
-content = '<!-- This is a generated file by regenerate_index_html.py. Do not modify !!!! -->\n\n'
+content = '<!-- This is a generated file by regenerate_index_html.py. Do not modify !!!! Modify index.html.in instead if you need to make changes-->\n\n'
content += open('index.html.in', 'rt').read().replace('${LINKS_WILL_BE_ADDED_HERE_BY_REGENERATE_INDEX_HTML}', '\n'.join(links)).replace('${TOTAL_SIZE}', total_size_str)
open('index.html', 'wt').write(content)