From c2209d01faadaf3daf715af1564aae20bae4790c Mon Sep 17 00:00:00 2001 From: wrought Date: Sat, 13 Sep 2014 21:07:09 -0700 Subject: [PATCH] moves files into an 'articles' dir for #39 --- jats-to-mediawiki.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/jats-to-mediawiki.py b/jats-to-mediawiki.py index e774156..10b40bc 100755 --- a/jats-to-mediawiki.py +++ b/jats-to-mediawiki.py @@ -153,8 +153,8 @@ def main(): # download the file archivefilename = wget.filename_from_url(archivefileurl) - if not os.path.exists(archivefilename): - urllib.urlretrieve(archivefileurl, archivefilename) + if not os.path.exists(destination + archivefilename): + urllib.urlretrieve(archivefileurl, destination + archivefilename) print "\nDownloading file..." else: print "\nFound local file, skipping download..." @@ -167,25 +167,24 @@ def main(): archivedirectoryname, archivefileextension = archivefilename.split( '.tar.gz') - if not os.path.exists(archivedirectoryname): + if not os.path.exists(destination + archivedirectoryname): print "\nExtracting " + archivedirectoryname + " ..." - tfile = tarfile.open(archivefilename, 'r:gz') - tfile.extractall('.') + tfile = tarfile.open(destination + archivefilename, 'r:gz') + tfile.extractall(destination) else: print "\nFound local directory, skipping extraction..." # run xsltproc # @TODO use list comprehension instead - for n in glob.glob(archivedirectoryname + "/*.nxml"): + for n in glob.glob(destination + archivedirectoryname + "/*.nxml"): nxmlfilepath = n print "\nConverting... " print nxmlfilepath - fullnxmlfilepath = cwd + "/" + nxmlfilepath - xsltoutputfile = open(articlepmcid + ".mw.xml", 'w') + xsltoutputfile = open(destination + articlepmcid + ".mw.xml", 'w') xslt_file = os.path.abspath( os.path.dirname(__file__)) + '/' + 'jats-to-mediawiki.xsl' xsltcommand = call( - ['xsltproc', xslt_file, fullnxmlfilepath], + ['xsltproc', xslt_file, nxmlfilepath], stdout=xsltoutputfile) print "\nReturning results..." if xsltcommand == 0: