Skip to content

Instantly share code, notes, and snippets.

@retorquere

retorquere/ris.py

Created May 4, 2021
Embed
What would you like to do?
#!/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