From: Thomas K. S. <csa...@ui...> - 2006-01-05 23:01:21
|
hello, although i'm a bloody beginner with python i dared to do some changes on bibtex2xml.py for my purposes it was useful to allow the script to take data from stdin if no argument is given. here the changed parts of the script: <snip_code> def contentshandler(filecontents_source): washeddata = bibtexwasher(filecontents_source) outdata = bibtexdecoder(washeddata) print '<?xml version="1.0" encoding="iso-8859-1"?>' #print '<?xml-stylesheet href="bibtexml.css" type="text/css" ?>' print '<!DOCTYPE bibtex:file PUBLIC' print ' "-//BibTeXML//DTD XML for BibTeX v1.0//EN"' print ' "bibtexml.dtd" >' print '<bibtex:file xmlns:bibtex="http://bibtexml.sf.net/">' print for line in outdata: print line print ' <!-- manual cleanup may be required... -->' print '</bibtex:file>' # just splitted of filehandling part def filehandler(filepath): try: fd = open(filepath, 'r') filecontents_source = fd.readlines() fd.close() except: print 'Could not open file:', filepath return filecontents_source # main program def main(): import sys if sys.argv[1:]: filepath = sys.argv[1] filecontents_source = filehandler(filepath) else: # instead of exit() read stdin here filecontents_source = sys.stdin.readlines() contentshandler(filecontents_source) if __name__ == "__main__": main() </snip_code> thanks to developers, this software was really useful to me... tom. |