old_contents: #! /usr/bin/env python
  
  """Run this during the week to write last week's short-form entry"""
  
  from __future__ import print_function
  
  from datetime import datetime, timedelta
  import errno
  import operator
  import os
  import sys
  
  ### date handling ###
  
  def sunday_after(dt, offset=1):
      """offset == 3 means 3rd Sunday from now, -2 means two Sundays back"""
      if offset == 0:
          raise ArgumentError("offset must be nonzero")
      if offset > 0:
          offset -= 1
      dt += timedelta(days=offset * 7)
  
      # 23:59:59 on next Sunday
      s = dt + timedelta(days=6 - dt.weekday())
      s = s.replace(hour=23, minute=59, second=59, microsecond=0)
  
      # Watch out for DST transition
      #s -= s.gmtoff - t.gmtoff
      return s
  
  
  ### getting a week's worth of tweets ###
  
  class Week:
  
      # Monday-to-Sunday week of tweets around mid_week
      def __init__(self, mid_week):
          latest = sunday_after(mid_week, 1)
          earliest = sunday_after(mid_week, -1)
          """r = Reader.new
          @tweets = []
          while true do
            tweet = r.next
            break if tweet.time <= earliest
            @tweets << tweet if tweet.time <= latest
          end"""
          class MockedTweet:
              def __init__(self, nr):
                  self.time = latest - timedelta(days=nr, hours=nr * 2, minutes=nr * 3)
              def __repr__(self):
                  return "\nMockedTweet from %s" % self.time
          self.tweets = [MockedTweet(1), MockedTweet(2), MockedTweet(3), MockedTweet(4)]
          self.tweets.sort(key=operator.attrgetter('time'))
  
      @property
      def sunday(self):
          return sunday_after(self.tweets[0].time)
  
  
  ### formatting the tweets ###
  
  def entry(tweets, sunday):
      return "blosxom entry for week ending %s:\n%r" % (sunday, tweets)
  
  
  ### main ###
  
  def main():
      w = Week(datetime.now() - timedelta(days=7))
      sunday = w.sunday
      year = '%04d' % sunday.year
      path = os.path.join('tweets', year[:-1] + 'x', year)
      try:
          os.makedirs(path)
      except OSError as e:
          if e.errno != errno.EEXIST:
              raise
      path = os.path.join(path, '%02d-%02d.txt' % (sunday.month, sunday.day))
      with open(path, 'w') as f:
          f.write(entry(w.tweets, sunday))
      print("Wrote", path)
  
  if __name__ == '__main__':
      main()
  
new_contents: #! /usr/bin/env python
  
  """Run this during the week to write last week's short-form entry"""
  
  from __future__ import print_function
  
  from datetime import datetime, timedelta
  import errno
  import operator
  import os
  import sys
  
  ### date handling ###
  
  def sunday_after(dt, offset=1):
      """offset == 3 means 3rd Sunday from now, -2 means two Sundays back"""
      if offset == 0:
          raise ArgumentError("offset must be nonzero")
      if offset > 0:
          offset -= 1
      dt += timedelta(days=offset * 7)
  
      # 23:59:59 on next Sunday
      s = dt + timedelta(days=6 - dt.weekday())
      s = s.replace(hour=23, minute=59, second=59, microsecond=0)
  
      # Watch out for DST transition
      #s -= s.gmtoff - t.gmtoff
      return s
  
  
  ### getting a week's worth of tweets ###
  
  class Week:
  
      # Monday-to-Sunday week of tweets around mid_week
      def __init__(self, mid_week):
          latest = sunday_after(mid_week, 1)
          earliest = sunday_after(mid_week, -1)
          """r = Reader.new
          @tweets = []
          while true do
            tweet = r.next
            break if tweet.time <= earliest
            @tweets << tweet if tweet.time <= latest
          end"""
          class MockedTweet:
              def __init__(self, nr):
                  self.time = latest - timedelta(days=nr, hours=nr * 2, minutes=nr * 3)
              def __repr__(self):
                  return "\nMockedTweet from %s" % self.time
          self.tweets = [MockedTweet(1), MockedTweet(2), MockedTweet(3), MockedTweet(4)]
          self.tweets.sort(key=operator.attrgetter('time'))
  
      @property
      def sunday(self):
          if self.tweets:
              return sunday_after(self.tweets[0].time)
  
  
  ### formatting the tweets ###
  
  def entry(tweets, sunday):
      return "blosxom entry for week ending %s:\n%r" % (sunday, tweets)
  
  
  ### main ###
  
  def main():
      w = Week(datetime.now() - timedelta(days=7))
      sunday = w.sunday
      if not sunday:  # no tweets last week
          return
      year = '%04d' % sunday.year
      path = os.path.join('tweets', year[:-1] + 'x', year)
      try:
          os.makedirs(path)
      except OSError as e:
          if e.errno != errno.EEXIST:
              raise
      path = os.path.join(path, '%02d-%02d.txt' % (sunday.month, sunday.day))
      with open(path, 'w') as f:
          f.write(entry(w.tweets, sunday))
      print("Wrote", path)
  
  if __name__ == '__main__':
      main()
  
subject: Handle weeks without tweets (what you say?!?)