Created
November 14, 2016 09:31
-
-
Save onurmatik/c4cec74e745cf6b2430dc4257d760dc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
FIXME: Cannot use C extensions. See below: | |
http://www.perrygeo.com/running-python-with-compiled-code-on-aws-lambda.html | |
http://stackoverflow.com/questions/34749806/using-moviepy-scipy-and-numpy-in-amazon-lambda | |
""" | |
from datetime import datetime | |
from urlparse import urlparse | |
from os import path | |
import boto3 | |
from chalice import Chalice | |
from pywb.rewrite.rewrite_live import LiveRewriter | |
from pywb.rewrite.url_rewriter import UrlRewriter | |
app = Chalice(app_name='archive') | |
app.debug = True | |
S3 = boto3.client('s3', region_name='us-east-1') | |
BUCKET = 'archive.do' | |
ENDPOINT = 'archive.do.s3-website-us-east-1.amazonaws.com' | |
@app.route('/{url+}') | |
def index(): | |
url = app.current_request.uri_params['url'] | |
parsed_url = urlparse(url) | |
wburl = path.join( | |
datetime.now().strftime('%Y/%m/%d/%H/%M'), | |
'%s%s' % (parsed_url.netloc, parsed_url.path), | |
'index.html', | |
) | |
urlrewriter = UrlRewriter(wburl) | |
liverewriter = LiveRewriter() | |
status_headers, buff = liverewriter.get_rewritten(url, urlrewriter) | |
S3.put_object( | |
Bucket=BUCKET, | |
Key=wburl, | |
Body=buff, | |
ContentType='text/html', | |
) | |
return { | |
'url': '%s/%s' % (ENDPOINT, wburl) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment