Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. def writeToFile( justOFname, htmlText, docNo, outputDir):
  2. """This function writes the htmlTEXT into the file. It also formats the document properly.
  3. Note that directory is the directory of the desired location. i.e. write /home/you/file directory will be /home/you
  4. Note that justOFname is just the ending of a filename"""
  5.  
  6. # Initialization
  7. docNo = str(docNo)
  8. justOFname = os.path.split(justOFname)[1]
  9.  
  10. body = "<TEXT>" + htmlText + "</TEXT>"
  11. textString = "<DOC><DOCNO>" + docNo + "</DOCNO>" + body + "</DOC>"
  12.  
  13. ########################################
  14. # Now output this to a file
  15.  
  16. # print "justOFname", justOFname
  17. # print "outputDir", outputDir
  18.  
  19. outputFname = os.path.sep.join( [outputDir, getNewFileName(justOFname)] )
  20. print "outputFname"
  21.  
  22. # Try to create the file first, if not, then make the directory and then apply it again
  23. try:
  24. _write( outputFname, textString)
  25.  
  26. except OSError, e:
  27. # File doesn't exist
  28. if e.error == 17:
  29. os.makedirs( outputDir )
  30. _write( outputFname, textString)
  31.  
  32. else:
  33. raise e
  34.  
  35. print "writeToFile suceed in writing to", outputFname
  36.  
  37.  
  38.  
  39. def _write( fname, stuff):
  40. """Internal function used by writeToFile"""
  41.  
  42. f = open( fname, 'w')
  43. f.write( stuff.encode("utf-8"))
  44. f.close()
  45.  
  46. ################
  47.  
  48. Traceback (most recent call last):
  49. File "main_walker.py", line 129, in <module>
  50. walk( sys.argv[1], sys.argv[2] )
  51. File "main_walker.py", line 38, in walk
  52. parseFunction( file, nameGenerator.getID(), outputFDir)
  53. File "/home/disappearedng/Desktop/SearchEngineProject/testEncoding/thirdTest/HtmlParser.py", line 59, in parseFile
  54. writeToFile( fileName, textString2, docNo , outputDir)
  55. File "/home/disappearedng/Desktop/SearchEngineProject/testEncoding/thirdTest/HtmlParser.py", line 95, in writeToFile
  56. raise e
  57. 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