Created
April 1, 2016 12:45
-
-
Save tanyuan/132d1849ac1486b8610626843334d60a to your computer and use it in GitHub Desktop.
Rename academic papers to author-year-title.pdf.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import bibtexparser | |
if __name__ == '__main__' : | |
parser = argparse.ArgumentParser(description='Extract bib file to author, year, and title.') | |
parser.add_argument('input', help='Input file (.bib)') | |
args = parser.parse_args() | |
filename = args.input | |
with open(filename) as bibtex_file: | |
bibtex_str = bibtex_file.read() | |
bib_database = bibtexparser.loads(bibtex_str) | |
authors = bib_database.entries[0]["author"] | |
year = bib_database.entries[0]["year"] | |
title = bib_database.entries[0]["title"] | |
authors_list = authors.split(" and ") | |
author = authors_list[0] | |
print(author, "-", year, "-", title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Rename academic paper PDF to author-year-title.pdf | |
# Example: | |
# INPUT: example.pdf | |
# OUTPUT: Tanyuan - 2016 - Human-Computer Interaction.pdf | |
# Dependencies: | |
# cb2bib | |
# python | |
# bibtexparser | |
usage(){ | |
echo "Usage: $0 PDF" | |
exit 1 | |
} | |
[[ $# -eq 0 ]] && usage | |
OLD_PDF=$1 | |
TMP=/tmp/rename-paper.bib | |
rm -f $TMP | |
# Get bib information and save to $TMP | |
cb2bib --doc2bib $OLD_PDF $TMP --sloppy | |
# Extract from bib | |
NEW_NAME=`python extract-bib.py $TMP` | |
echo "author - year - title" | |
echo "+++++++++++++++++++++" | |
echo $NEW_NAME | |
# Rename original PDF | |
mv $OLD_PDF "$NEW_NAME".pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment