Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created May 4, 2021 23:38
#!/usr/bin/env python
# run as ris.py importdir1 importdir2 ...
import glob, sys, os, re
ris = ''
for importdir in sys.argv[1:]:
for pdf in glob.glob(os.path.join(importdir, '*.pdf')):
m = re.match(r'^(.+?)@(.+?)\$(.+?).pdf$', os.path.basename(pdf))
if m:
title, author, year = [g.strip() for g in m.groups()]
ris += 'TY - JOUR\n'
ris += 'TI - ' + title + '\n'
ris += 'AU - ' + author + '\n'
ris += 'DA - ' + year + '///\n'
ris += 'PY - ' + year + '\n'
ris += 'L1 - ' + pdf + '\n'
ris += 'ER -\n'
ris += '\n'
print(ris) # or write it to a file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment