Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created May 4, 2021 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retorquere/c8d125e083d2a1222c3e73fd0639205c to your computer and use it in GitHub Desktop.
Save retorquere/c8d125e083d2a1222c3e73fd0639205c to your computer and use it in GitHub Desktop.
#!/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