You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyris.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """ Takes an input citation file and formats it as a Refman (RIS) file.
  2. """
  3. __author__ = "Noëlle Anthony"
  4. __version__ = "0.1.0"
  5. import sys, os
  6. class Citation:
  7. def __init__(self, filename):
  8. chunks = filename.split(".")
  9. if len(chunks) == 1: # has no extension
  10. self.fn, self.ext = chunks[0], ""
  11. elif len(chunks) >= 3: # has multiple periods in filename, last one indicates extension
  12. self.fn, self.ext = ".".join(chunks[:-1]), chunks[-1]
  13. else: # has one period in filename
  14. self.fn, self.ext = chunks[0], chunks[1]
  15. with open(filename, 'r') as f:
  16. self.contents = f.read()
  17. self.outfile = self.fn + ".ris"
  18. def toString(self):
  19. rstr = "Current infile: {}.{}".format(self.fn, self.ext)
  20. rstr += "\n"
  21. rstr += "Current outfile: {}".format(self.outfile)
  22. return rstr
  23. def print(self):
  24. rstr = "Current infile: {}.{}".format(self.fn, self.ext)
  25. rstr += "\n"
  26. rstr += "Current outfile: {}".format(self.outfile)
  27. print(rstr)
  28. def main(filename):
  29. cite = Citation(filename)
  30. if __name__ == "__main__":
  31. args = sys.argv()
  32. if len(args) < 2:
  33. print("Input file required.")
  34. os.exit(0)
  35. main(args[1])