20.23 Research support tasks

Work-in-progress

  • Collecting PDFs for journals
  • Collecting PDFs for review (databases, authors, inter-library loans)
  • Checking references
  • Formatting documents

Get the latest journal PDFs available:

import os, re

root_directory = "/home/gerit/ownCloud/data/journals"

def get_latest_directory(directories):
    """Get the latest directory based on volume_number or numeric format."""
    pattern = re.compile(r"^\d+(_\d+)?$|^\d+$")
    valid_dirs = [d for d in directories if pattern.match(d)]
    
    if not valid_dirs:
        return None
    
    return max(valid_dirs, key=lambda d: int(d.split('_')[0]))


for first_level_dir in os.listdir(root_directory):
    first_level_path = os.path.join(root_directory, first_level_dir)
    
    if os.path.isdir(first_level_path):
        second_level_dirs = [
            d for d in os.listdir(first_level_path)
            if os.path.isdir(os.path.join(first_level_path, d))
        ]
        
        if second_level_dirs:
            try:
                latest_dir = get_latest_directory(second_level_dirs)
                print(f"Latest directory in '{first_level_path}': {latest_dir}")
            except ValueError as exc:
                print(exc)