Skip to content

Instantly share code, notes, and snippets.

@cpmpercussion
Created August 6, 2024 13:29
Show Gist options
  • Save cpmpercussion/2d9c84344ee0f7e123571a3aa2a7bdce to your computer and use it in GitHub Desktop.
Save cpmpercussion/2d9c84344ee0f7e123571a3aa2a7bdce to your computer and use it in GitHub Desktop.
Generate a Bibtex file from the NIME2023 proceedings from a CSV file with the metadata
import csv
import shutil
from pypdf import PdfReader
# Move PDF files to proceedings format
PAPERS_IN_DIR = "20240201-cr-files"
PAPERS_OUT_DIR = "NIME2023-proceedings"
def convert_csv_to_bibtex(csv_file, bibtex_file, copy_files = False):
"""Convert a CSV file to BibTeX format"""
with open(csv_file, newline="", encoding="utf-8-sig") as csvfile:
reader = csv.DictReader(csvfile)
prev_last_page = 0 # for tracking page numbers through the proceedings
with open(bibtex_file, "w", encoding="utf-8") as bibtexfile:
for row in reader:
# read data out of the CSV
cmt_id = row["cmtID"]
number = row["number"]
key = f"nime2023_{number}"
author = row["proc-authors"]
author = author.replace(";", " and").rstrip()
title = row["title"]
booktitle = "Proceedings of the International Conference on New Interfaces for Musical Expression"
editor = "Miguel Ortiz and Adnan Marquez-Borbon"
year = "2023"
month = "May"
address = "Mexico City, Mexico"
issn = "2220-4806"
url = f"http://nime.org/proceedings/{year}/{key}.pdf"
track = row["track"]
# note = row["presentation"]
abstract = row["abstract"]
# calculate page number
src = f"{PAPERS_IN_DIR}/{cmt_id}.pdf"
dst = f"{PAPERS_OUT_DIR}/{key}.pdf"
src_paper_reader = PdfReader(src)
num_pages = len(src_paper_reader.pages)
print(f"Num pages: {num_pages}")
# Page counting logic.
first_page = prev_last_page + 1
last_page = prev_last_page + num_pages
prev_last_page = last_page
bibtex_entry = f"@article{{{key},\n" \
f" author = {{{author}}},\n" \
f" title = {{{title}}},\n" \
f" pages = {{{first_page}--{last_page}}},\n" \
f" numpages = {{{num_pages}}},\n" \
f" booktitle = {{{booktitle}}},\n" \
f" editor = {{{editor}}},\n" \
f" year = {{{year}}},\n" \
f" month = {{{month}}},\n" \
f" address = {{{address}}},\n" \
f" issn = {{{issn}}},\n" \
f" url = {{{url}}},\n" \
f" articleno = {{{number}}},\n" \
f" track = {{{track}}},\n" \
f" abstract = {{{abstract}}}\n" \
f"}}\n\n"
bibtexfile.write(bibtex_entry)
if copy_files:
print(f"Copying: {src} to {dst}.")
shutil.copyfile(src, dst)
# Example usage
PAPERS_CSV_FILE = "NIME2023 Program - Data Matching/nime23-proceedings-finalised-proceedings.csv"
# Do the Conversion
convert_csv_to_bibtex(PAPERS_CSV_FILE, "nime2023_papers.bib", copy_files=True)
# f"@inproceedings{article_id,
# urlsuppl1 = {},
# urlsuppl2 = {},
# urlsuppl3 = {},
# pdf = {},
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment