1234567891011121314151617181920212223242526272829303132333435363738 |
- 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 = """
- <html>
- <body>
- {}
- </body>
- </html>
- """
- feed_links = [
- '<li><a href="{0[url]}">{0[title]}</a></li>'.format(feed)
- for feed in feed_index.values()
- ]
- html = index_template.format('<br>\n'.join(feed_links))
- s3.put_object(
- Bucket=bucket,
- Key='index.html',
- Body=html,
- ContentType='text/html'
- )
|