Display pages by date

In [1]:
import pandas as pd
import ipywidgets as widgets
import arrow
import datetime
from pathlib import Path
from IPython.display import display, HTML, Image
In [2]:
dfs = []
for year in range(1901, 1909):
    df = pd.read_csv(f'{year}_with_dates.csv', parse_dates=['page_date'])
    dfs.append(df[['directory', 'name', 'page_date']])
df_all = pd.concat(dfs)
In [3]:
def find_pages(b):
    results.clear_output()
    images = []
    pages = df_all.loc[df_all['page_date'] == pd.Timestamp(date_picker.value)]
    for page in pages.itertuples():
        print(page)
        image_name = f'{page.name.split(".")[0]}-header.jpg'
        image_path = Path(f'all_headers/{page.directory}/{image_name}')
        images.append(image_path)
    with results:
        for image in images:
            print(image)
            display(Image(filename=str(image)))
            
In [4]:
date_picker = widgets.DatePicker(
    description='Pick a Date',
    disabled=False,
    value=datetime.date(1901, 1, 7)
)

find = widgets.Button(
    description='Find pages',
    disabled=False,
    button_style='primary', # 'success', 'info', 'warning', 'danger' or ''
    tooltip='Click me',
    icon='search'
)

find.on_click(find_pages)
results = widgets.Output()
#display(widgets.VBox([widgets.HBox([date_picker, find]), results]))
display(date_picker)
display(find)
display(results)
In [ ]: