Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def writeToFile( justOFname, htmlText, docNo, outputDir):
- """This function writes the htmlTEXT into the file. It also formats the document properly.
- Note that directory is the directory of the desired location. i.e. write /home/you/file directory will be /home/you
- Note that justOFname is just the ending of a filename"""
- # Initialization
- docNo = str(docNo)
- justOFname = os.path.split(justOFname)[1]
- body = "<TEXT>" + htmlText + "</TEXT>"
- textString = "<DOC><DOCNO>" + docNo + "</DOCNO>" + body + "</DOC>"
- ########################################
- # Now output this to a file
- # print "justOFname", justOFname
- # print "outputDir", outputDir
- outputFname = os.path.sep.join( [outputDir, getNewFileName(justOFname)] )
- print "outputFname"
- # Try to create the file first, if not, then make the directory and then apply it again
- try:
- _write( outputFname, textString)
- except OSError, e:
- # File doesn't exist
- if e.error == 17:
- os.makedirs( outputDir )
- _write( outputFname, textString)
- else:
- raise e
- print "writeToFile suceed in writing to", outputFname
- def _write( fname, stuff):
- """Internal function used by writeToFile"""
- f = open( fname, 'w')
- f.write( stuff.encode("utf-8"))
- f.close()
- ################
- Traceback (most recent call last):
- File "main_walker.py", line 129, in <module>
- walk( sys.argv[1], sys.argv[2] )
- File "main_walker.py", line 38, in walk
- parseFunction( file, nameGenerator.getID(), outputFDir)
- File "/home/disappearedng/Desktop/SearchEngineProject/testEncoding/thirdTest/HtmlParser.py", line 59, in parseFile
- writeToFile( fileName, textString2, docNo , outputDir)
- File "/home/disappearedng/Desktop/SearchEngineProject/testEncoding/thirdTest/HtmlParser.py", line 95, in writeToFile
- raise e
- IOError: [Errno 2] No such file or directory: '/home/disappearedng/Desktop/SearchEngineProject/testingscript/dummy/output/59.75.129.121/jxcg/picture_html.TREC'
Add Comment
Please, Sign In to add comment