old_contents: from os import listdir
  from sentenceSelection import selectSentences
  import json
  
  INFO_DICT = "./hnSummarized/info.json"
  TEXT_DIR = "./hnSummarized/text/"
  
  infoFile = file(INFO_DICT, "r")
  info = json.load(infoFile)
  
  OUT ="""
  <!DOCTYPE html>
  <html lang="en">
  
  <head>
    <title>HN Summarized</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="custom.css">
  </head>
  
  <body>
  
  <div class="jumbotron">
      <h1 class="text-center">HN Summarized</h1> 
  </div>
  """
  
  ROW = '<div class="row">'
  ELE = """
      <div class="col-sm-6">
          <div class="container-fluid">
  """
  ELE_END = """
          </div>
      </div>
  """
  ROW_END = "</div>\n"
  
  PAGE_END = """
  </body>
  </html>
  """
  
  def block(title, summary, article, comments):
      ele = """
      <div class="col-sm-6">
          <div class="container-fluid">
              <h3 class ="text-center">{0}</h3>  
              <blockquote>
                  <p>
                      {1}
                  </p>
                  <footer>
                      <a href ="{2}">Article</a> | <a href="{3}">HN Comments</a>
                  </footer>
              </blockquote>
          </div>
      </div>
  """
      return ele.format(title, summary, article, comments)
  
  
  ADD_ROW_BEFORE = True
  
  for folder in listdir(TEXT_DIR):
      for downFile in listdir(TEXT_DIR + folder):
          fileID = downFile.split(".")[0]
  
          path = TEXT_DIR + folder + "/" + downFile
  
          # Load text
          rawFile = file(path, "r")
          rawText = rawFile.read()
          rawFile.close()
          sumSents = selectSentences(rawText, 10)
  
          if ADD_ROW_BEFORE:
              OUT += ROW
  
          title = info[fileID]["title"].encode("ascii", "ignore")
          summary = sumSents.encode("ascii", "ignore")
          article = info[fileID]["url"].encode("ascii", "ignore")
          comments = info[fileID]["comments"].encode("ascii", "ignore")
  
          OUT += block(title, summary, article, comments)
  
          if not ADD_ROW_BEFORE: #False
              OUT += ROW_END
              ADD_ROW_BEFORE = True
          else:
              ADD_ROW_BEFORE = False
  
  ofile = file("out.html", "w+")
  ofile.write(OUT)
  ofile.close()
  
  
new_contents: import os
  
  from sentenceSelection import selectSentences
  
  
  TEXT_DIR = "./hnSummarized/text/"
  SUM_DIR = "./hnSummarized/summaries/"
  NUM_SENTENCES = 10
  
  def getFolder(folder, name):
      path = SUM_DIR + folder +"/"
      fName = name
      try:
          os.makedirs(path)
      except OSError:
          if not os.path.isdir(path):
              print "Error on making folder: ", d
      return path + fName
  
  for folder in os.listdir(TEXT_DIR):
      for downFile in os.listdir(TEXT_DIR + folder):
          path = TEXT_DIR + folder + "/" + downFile
  
          # Load text
          rawFile = file(path, "r")
          rawText = rawFile.read()
          rawFile.close()
  
          # Summarise
          summary = selectSentences(rawText, NUM_SENTENCES)
  
          # Key Words
          keyWordsList = ["One, two, three"]
          keyWords = keyWordsList[0] + " | ".join(keyWordsList[1:])
  
          toSave = keyWords + "\n" + summary
  
          savePath = getFolder(folder, downFile)
          rawFile = file(savePath, "w+")
          rawFile.write(toSave)
          rawFile.close()
  
subject: Save summaries