old_contents: """
  A script to obtain the Ashlock Fingerprints of all strategies in the Axelrod
  library.
  
  This writes a hash of the source code of each strategy to file: db.csv.
  
  If the source code of a strategy changes **or** a new strategy is introduced
  then the fingerprint is regenerated for that strategy.
  """
  
  import inspect
  import hashlib
  import csv
  
  import axelrod as axl
  
  def write_strategy_to_db(strategy, filename="db.csv"):
      """
      Write the hash of a strategy to the db
      """
      source_code = "".join(inspect.getsourcelines(strategy)[0])
      hash_object = hashlib.md5(source_code.encode('utf-8'))
      hashed_source = hash_object.hexdigest()
      with open(filename, "a") as db:
          db.write("{},{}\n".format(strategy.name, hashed_source))
  
  def read_db(filename="db.csv"):
      """
      Read filename and return a dictionary mapping string names to hash of source
      code of a strategy
      """
      with open(filename, "r") as db:
          csvreader = csv.reader(db)
          str_to_hash = {row[0]: row[1] for row in csvreader}
      return str_to_hash
  
  def obtain_fingerprint(strategy, probe=axl.TitForTat):
      """
  	Obtain the fingerprint for a given strategy and save the figure to the
      assets dir
      """
      fp = axl.AshlockFingerprint(strategy, probe)
      fp.fingerprint(progress_bar=False, processes=0)
      plot = fp.plot()
      plot.savefig("assets/{}.png".format(strategy.name))
  
  def write_markdown(strategy):
      """
      Write a markdown section of a strategy.
  
      """
      markdown = """
  
  ## {}
  
  ![fingerprint of {}](./assets/{}.png)
      """.format(strategy.name, strategy.name, strategy.name)
      return markdown
  
  def main():
      """
      Fingerprint all strategies, if a strategy has already been fingerprinted it
      does not get rerun.
      """
      version = axl.__version__
  
      markdown = """# Ashlock fingerprints
  
  See:
  [axelrod.readthedocs.io/en/latest/tutorials/further_topics/fingerprinting.html#fingerprinting] (http://axelrod.readthedocs.io/en/latest/tutorials/further_topics/fingerprinting.html#fingerprinting)
  
  All strategies included from Axelrod version {}.
  
  This README.md file is autogenerated by running:
  
  ```python
  $ python update_fingerprints.py
  ```
  
  Each individual fingerprint can be obtained by running:
  
  ```python
  import axelrod as axl
  fp = axl.AshlockFingerprint(strategy, probe)
  fp.fingerprint()
  fp.plot()
  ```
      """.format(version)
  
      db = read_db()
      for strategy in axl.strategies:
          if strategy.name not in db:
              obtain_fingerprint(strategy)
              write_strategy_to_db(strategy)
          markdown += write_markdown(strategy)
  
      with open("README.md", "w") as outfile:
          outfile.write(markdown)
  
  
  if __name__ == "__main__":
      main()
  
new_contents: """
  A script to obtain the Ashlock Fingerprints of all strategies in the Axelrod
  library.
  
  This writes a hash of the source code of each strategy to file: db.csv.
  
  If the source code of a strategy changes **or** a new strategy is introduced
  then the fingerprint is regenerated for that strategy.
  """
  
  import inspect
  import hashlib
  import csv
  
  import axelrod as axl
  
  def write_strategy_to_db(strategy, filename="db.csv"):
      """
      Write the hash of a strategy to the db
      """
      source_code = "".join(inspect.getsourcelines(strategy)[0])
      hash_object = hashlib.md5(source_code.encode('utf-8'))
      hashed_source = hash_object.hexdigest()
      with open(filename, "a") as db:
          db.write("{},{}\n".format(strategy.name, hashed_source))
  
  def read_db(filename="db.csv"):
      """
      Read filename and return a dictionary mapping string names to hash of source
      code of a strategy
      """
      with open(filename, "r") as db:
          csvreader = csv.reader(db)
          str_to_hash = {row[0]: row[1] for row in csvreader}
      return str_to_hash
  
  def obtain_fingerprint(strategy, probe=axl.TitForTat):
      """
  	Obtain the fingerprint for a given strategy and save the figure to the
      assets dir
      """
      fp = axl.AshlockFingerprint(strategy, probe)
      fp.fingerprint(progress_bar=False, processes=0)
      plot = fp.plot()
      plot.savefig("assets/{}.png".format(strategy.name))
  
  def write_markdown(strategy):
      """
      Write a markdown section of a strategy.
  
      """
      markdown = """
  
  ## {}
  
  ![fingerprint of {}](./assets/{}.png)
      """.format(strategy.name, strategy.name, strategy.name)
      return markdown
  
  def main():
      """
      Fingerprint all strategies, if a strategy has already been fingerprinted it
      does not get rerun.
      """
      version = axl.__version__
  
      markdown = """# Ashlock fingerprints
  
  See:
  [axelrod.readthedocs.io/en/latest/tutorials/further_topics/fingerprinting.html#fingerprinting] (http://axelrod.readthedocs.io/en/latest/tutorials/further_topics/fingerprinting.html#fingerprinting)
  
  All strategies included from Axelrod version {}.
  
  This README.md file is autogenerated by running:
  
  ```
  $ python update_fingerprints.py
  ```
  
  Each individual fingerprint can be obtained by running:
  
  ```python
  import axelrod as axl
  fp = axl.AshlockFingerprint(strategy, probe)
  fp.fingerprint()
  fp.plot()
  ```
      """.format(version)
  
      db = read_db()
      for strategy in axl.strategies:
          if strategy.name not in db:
              obtain_fingerprint(strategy)
              write_strategy_to_db(strategy)
          markdown += write_markdown(strategy)
  
      with open("README.md", "w") as outfile:
          outfile.write(markdown)
  
  
  if __name__ == "__main__":
      main()
  
subject: Correct md code format.