def write_index(bucket, feed_data): try: index = s3.get_object( Bucket=bucket, Key='feeds.json',) feed_index = json.load(index['Body']) except ClientError as e: error_code = e.response['Error']['Code'] if error_code == 'NoSuchKey': feed_index = {} else: raise e feed_path = feed_data['encoded_path'] feed_index[feed_path] = feed_data s3.put_object( Bucket=bucket, Key='feeds.json', Body=json.dumps(feed_index, indent=4), ContentType='application/json' ) index_template = """ {} """ feed_links = [ '
  • {0[title]}
  • '.format(feed) for feed in feed_index.values() ] html = index_template.format('
    \n'.join(feed_links)) s3.put_object( Bucket=bucket, Key='index.html', Body=html, ContentType='text/html' )