quatuorbellefeuille.com

Content, build scripts and admin scripts for the Bellefeuille Quartet website.
git clone https://git.kevinlegouguec.net/quatuorbellefeuille.com
Log | Files | Refs

renamelogs.py (670B)


      1 #!/usr/bin/env python3
      2 
      3 from datetime import datetime
      4 from os import rename
      5 from pathlib import Path
      6 import re
      7 from sys import argv
      8 
      9 
     10 ACCESS_RE = re.compile(' '.join((
     11     r'\S+',
     12     r'\S+',
     13     r'\S+',
     14     r'\[(?P<date>[^:]+):\S+ \S+\]',
     15     r'"GET [^ ?]+(\?\S+)? [^"]+"',
     16     r'200 [0-9]+',
     17     r'"[^"]+(\?\S+)?"',
     18     r'"[^"]+"'
     19 )))
     20 
     21 DATE_FMT = '%d/%b/%Y'
     22 
     23 
     24 def main(paths):
     25     for p in paths:
     26         with open(p) as f:
     27             date = ACCESS_RE.search(f.read()).group('date')
     28 
     29         date = datetime.strptime(date, DATE_FMT)
     30         new_path = Path(p).with_name(date.strftime('%F'))
     31         rename(p, new_path)
     32 
     33 
     34 if __name__ == '__main__':
     35     main(argv[1:])