Skip to content

Instantly share code, notes, and snippets.

@Matts966
Created January 19, 2020 08:10
Show Gist options
  • Select an option

  • Save Matts966/443e32680477cf476532598a0628fd82 to your computer and use it in GitHub Desktop.

Select an option

Save Matts966/443e32680477cf476532598a0628fd82 to your computer and use it in GitHub Desktop.
.ris file to citation list
from sys import stdin
index = 0
finding_author = False
author = ""
finding_publish_year = False
publish_year = ""
etal = False
for line in stdin:
if line.startswith("TI"):
index += 1
finding_author = True
finding_publish_year = True
elif finding_author and line.startswith("AU"):
author = line.split()[2][:-1] + " "
finding_author = False
etal = False
elif not finding_author and not etal and line.startswith("AU"):
author += "et al., "
etal = True
elif finding_publish_year and line.startswith("PY"):
publish_year = line.split()[2]
finding_publish_year = False
if not etal:
author += ".,"
print(str(index) + ". " + author + publish_year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment