import boto3
import re

client = boto3.client('dynamodb')

base_html = """
<!DOCTYPE html>
<html lang="en-us">
<title>Gitshame</title>
<meta charset=UTF-8" />
<link href="//s3.amazonaws.com/gitshame-html/main.css" rel="stylesheet" type="text/css">
<link href="//s3.amazonaws.com/gitshame-html/icon.png" rel="icon" type="image/png">
<script src="//s3.amazonaws.com/gitshame-html/main.js"></script>

<body>
  <div class="nav">
    <h1 class="title"> Gitshame </h1>
    <button type="button" class="shame groove" onclick="openModal()"> Shame! </button>
  </div>
  <div id="modal" onclick="closeModalEvent(event)">
    <div class="groove">
      <h3> Enter a shameful github link </h3>
      <input id="link" type="text" name="link">
      <input type="button" value="Shame!" onclick="shame()">
    </div>
  </div>

"""

def get_item_for_sha(sha):
  return client.get_item(
    TableName='gitshame-chunks',
    Key={
      'sha': {
        'S': sha
      }
    }
  )

def handler(event, context):
  item_sha = event['sha']
  html = get_item_for_sha(item_sha)['Item']['html']['S']
  html_chunk = '<div class="wrapper groove">' + html + '</div>'
  page_html = base_html + html_chunk + '</body></html>'

  return page_html

@@ -52,20 +52,23 @@
 modb')%0A%0A
-base
+opening
 _html = 
@@ -813,16 +813,49 @@
 %3E%0A%0A%22%22%22%0A%0A
+closing_html = '%3C/body%3E%3C/html%3E'%0A%0A
 def get_
@@ -991,16 +991,24 @@
    %7D%0A  )
+%5B'Item'%5D
 %0A%0Adef ha
@@ -1097,16 +1097,8 @@
 a)%5B'
-Item'%5D%5B'
 html
@@ -1187,12 +1187,15 @@
 l = 
-base
+opening
 _htm
@@ -1211,32 +1211,28 @@
 chunk + 
-'%3C/body%3E%3C/
+closing_
 html
-%3E'
 %0A%0A  retu

improve readability of page html