title: Split diary file into multiple files using Python
body: <p>I keep a diary file of tech notes. Each entry is timestamped like so:</p>
  
  <pre><code># Monday 02012-05-07 at 01:45:20 PM
  
  This is a sample note
  
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
  quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
  cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
  proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  
  # Wednesday 02012-06-06 at 03:44:11 PM
  
  Here is another one.
  
  Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia 
  deserunt mollit anim id est laborum.
  </code></pre>
  
  <p>Would like to break these notes down into individual files based on timestamp headers. e.g. <code>This is a sample note.txt</code>, <code>Here is another really long title.txt</code>. Im sure I would have to truncate the filename at some point, but the idea would be to seed the filename based on the first line of the diary entry.</p>
  
  <p>It doesn't look like I can modify the file's creation date via python, so I would like to preserve the entries timestamp as part of the note's body.</p>
  
  <p>I've got a RegEx pattern to capture the timestamps that suits me well:</p>
  
  <pre><code>#(\s)(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)(\s)(.*)
  </code></pre>
  
  <p>and can likely use that regex to loop through the file and break each entry down, but im not quite sure how to loop through the diary file and break it out into individual files. There are a lot of examples of grabbing the actual regex pattern, or particular line, but I want to do a few more things here and am having some difficulty peicing it together.</p>
  
  <p>Here is an example of the desired file contents (datestamp + all text up until next datestamp match):</p>
  
  <pre><code>bash$ cat This\ is\ a\ sample\ note.txt
  Monday 02012-05-07 at 01:45:20 PM
  
  This is a sample note
  
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
  quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
  cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
  proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  
  bash$
  </code></pre>