From 3c486cc758bb8ceb7a2dd0a1d74e0f4a7103e818 Mon Sep 17 00:00:00 2001 From: Josh Dillon Date: Wed, 20 Jul 2022 16:55:27 -0700 Subject: [PATCH] Add human readable dates to READMEs This also addresses https://github.com/HERA-Team/hera_notebook_templates/issues/21 --- .../v1/stage_1_task_scripts/build_notebook_readme.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pipelines/h5c/rtp/v1/stage_1_task_scripts/build_notebook_readme.py b/pipelines/h5c/rtp/v1/stage_1_task_scripts/build_notebook_readme.py index 1c18da81..697ee9e8 100755 --- a/pipelines/h5c/rtp/v1/stage_1_task_scripts/build_notebook_readme.py +++ b/pipelines/h5c/rtp/v1/stage_1_task_scripts/build_notebook_readme.py @@ -6,6 +6,7 @@ import argparse import os import glob +from astropy.time import Time starting_dir = os.getcwd() @@ -34,10 +35,17 @@ # build repo readme = ['# Links to view files:', ''] for file in sorted(glob.glob('*')): + try: # try to append dates in a parethetical + JD = os.path.splitext(file)[0].split('_')[-1] + utc = Time(JD, format='jd').datetime + date_str = f' ({utc.year}-{utc.month}-{utc.day})' + except: + date_str = '' + if file.endswith('.html'): - readme.append(f'* [{file}](https://htmlpreview.github.io/?https://github.com/{user}/{repo}/blob/{branch}/{sub_folders}/{file})') + readme.append(f'* [{file}{date_str}](https://htmlpreview.github.io/?https://github.com/{user}/{repo}/blob/{branch}/{sub_folders}/{file})') elif file.endswith('.ipynb'): - readme.append(f'* [{file}](https://nbviewer.jupyter.org/github/{user}/{repo}/blob/{branch}/{sub_folders}/{file})') + readme.append(f'* [{file}{date_str}](https://nbviewer.jupyter.org/github/{user}/{repo}/blob/{branch}/{sub_folders}/{file})') with open('README.md', 'w') as f: