Created
February 6, 2019 08:24
-
-
Save abhiyerra/7dcd96741cf98a1823da91f32b50020d 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
# TODO: | |
# - [ ] Embedly | |
# - | |
require "httparty" | |
require "aws-sdk-s3" | |
SITES = [ | |
{ | |
paper: "https://paper.dropbox.com/doc/...", | |
filename: "index.html", | |
title: "Abhi Yerra", | |
s3_bucket: "abhiyerra.com", | |
aws_access_key_id: "", | |
aws_secret_access_key: "", | |
aws_region: "us-east-1", | |
ga: "UA-34234404-1", | |
}, | |
] | |
class Dropbox | |
def self.get_paper_doc(doc_id) | |
response = HTTParty.post( | |
"https://api.dropboxapi.com/2/paper/docs/download", | |
headers: { | |
"Authorization" => "Bearer INSERT_TOKEN_HERE", | |
"Dropbox-API-Arg" => { | |
"doc_id" => doc_id, | |
"export_format" => { | |
".tag" => "html", | |
}, | |
}.to_json, | |
"Content-Type" => "text/plain; charset=utf-8", | |
}, | |
) | |
return response.body.to_s.encode("UTF-8", invalid: :replace, undef: :replace, replace: "") | |
end | |
end | |
class Site | |
def self.create(s) | |
doc_id = s[:paper].split("-")[-1] | |
html_doc = Dropbox.get_paper_doc(doc_id) | |
doc = %{ | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" | |
crossorigin="anonymous"> | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-34234404-1"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', '#{s[:ga]}'); | |
</script> | |
<title>#{s[:title]}</title> | |
</head> | |
<body> | |
<div class="container"> | |
#{html_doc} | |
</div> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" | |
crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" | |
crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" | |
crossorigin="anonymous"></script> | |
</body> | |
</html> | |
} | |
puts s | |
s3 = Aws::S3::Resource.new( | |
access_key_id: s[:aws_access_key_id], | |
secret_access_key: s[:aws_secret_access_key], | |
region: s[:aws_region], | |
) | |
obj = s3.bucket(s[:s3_bucket]).object(s[:filename]) | |
obj.put(acl: "public-read", body: doc) | |
end | |
end | |
def handler(event:, context:) | |
SITES.each do |site| | |
Site.create(site) | |
end | |
end | |
handler(event: nil, context: nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment