Skip to content

Commit

Permalink
Create 2024csv2bib.py
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanofasciani committed Sep 9, 2024
1 parent 3179151 commit bc15ce0
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions scripts/2024csv2bib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import re
import csv
import shutil
from pypdf import PdfReader


# Move PDF files to proceedings format
PAPERS_IN_DIR = "NIME2024-camera-ready"
PAPERS_OUT_DIR = "NIME2024-paper-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"nime2024_{number}"
author = row["proc-authors"]
author = re.sub("([\(]).*?([\)])", "\g<1>\g<2>", author)
author = re.sub("[()*]", '', author)
author = re.sub(r";", "and", author)
title = row["title"]
booktitle = "Proceedings of the International Conference on New Interfaces for Musical Expression"
editor = "Astrid Bin and Courtney Nicole Reed"
year = "2024"
month = "September"
address = "Utrecht, Netherlands"
issn = "2220-4806"
url = f"http://nime.org/proceedings/{year}/{key}.pdf"
track = row["track"]
video = row["video"]
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" presentation-video = {{{video}}},\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 = "./NIME2024.csv"

# Do the Conversion
convert_csv_to_bibtex(PAPERS_CSV_FILE, "nime2024_papers.bib", copy_files=True)



# f"@inproceedings{article_id,
# urlsuppl1 = {},
# urlsuppl2 = {},
# urlsuppl3 = {},
# pdf = {},
# }

0 comments on commit bc15ce0

Please sign in to comment.