{"action":"created","comment":{"url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/comments/77162281","id":77162281,"diff_hunk":"@@ -0,0 +1,161 @@\n+# -*- coding: utf-8 -*-\n+\n+# Method for converting MD files to HTML\n+\n+from __future__ import print_function, unicode_literals\n+\n+import codecs\n+import os\n+import re\n+import shutil\n+import tempfile\n+from contextlib import closing\n+import markdown\n+import boto3\n+import datetime\n+\n+from glob import glob\n+from general_tools.file_utils import unzip, add_file_to_zip, make_dir, write_file\n+from general_tools.print_utils import print_error, print_ok\n+from general_tools.url_utils import download_file\n+\n+class TransformOBS(object):\n+\n+    dirRe = re.compile(r'(<div\\s.*?class=\".*?obs-content.*?\">).*?(</div>)', re.UNICODE + re.DOTALL)\n+\n+    def __init__(self, source_url, outputDir, options):\n+        self.source_url = source_url\n+        self.outputDir = outputDir\n+        self.options = options\n+\n+        self.downloadDir = tempfile.mkdtemp(prefix='download_')\n+        self.filesDir = tempfile.mkdtemp(prefix='files_')\n+        self.errors = []\n+\n+    def close(self):\n+        # delete temp files\n+        if os.path.isdir(self.downloadDir):\n+            shutil.rmtree(self.downloadDir, ignore_errors=True)\n+        if os.path.isdir(self.filesDir):\n+            shutil.rmtree(self.filesDir, ignore_errors=True)\n+\n+    def run(self):\n+        try:\n+            # download the archive\n+            fileToDownload = self.source_url\n+            filename = self.source_url.rpartition('/')[2]\n+            downloadedFile = os.path.join(self.downloadDir, filename)\n+            try:\n+                print('Downloading {0}...'.format(fileToDownload), end=' ')\n+                if not os.path.isfile(downloadedFile):\n+                    download_file(fileToDownload, downloadedFile)\n+            finally:\n+                print('finished.')\n+\n+            # unzip the archive\n+            try:\n+                print('Unzipping...'.format(downloadedFile), end=' ')\n+                unzip(downloadedFile, self.filesDir)\n+            finally:\n+                print('finished.')\n+\n+            # create output directory\n+            make_dir(self.outputDir)\n+\n+            # read the markdown files and output html files\n+            try:\n+                print('Processing the OBS markdown files')\n+\n+                files_to_process = sorted(glob(os.path.join(self.filesDir, '*.md')))\n+\n+                currentDir = os.path.dirname(os.path.realpath(__file__))\n+                with codecs.open(os.path.join(currentDir, 'template.html'), 'r', 'utf-8-sig') as html_file:\n+                    html_template = html_file.read()\n+\n+                completeHtml = ''\n+                for filename in files_to_process:\n+                   # read the markdown file\n+                    with codecs.open(filename, 'r', 'utf-8-sig') as md_file:\n+                        md = md_file.read()\n+                        html = markdown.markdown(md)\n+                        completeHtml += html\n+                        html = TransformOBS.dirRe.sub(r'\\1\\n' + html + r'\\n\\2', html_template)","path":"functions/convert/main.py","position":82,"original_position":82,"commit_id":"6dfaf2ff86ffafb2e67785df9b429ba8039aa19f","original_commit_id":"6dfaf2ff86ffafb2e67785df9b429ba8039aa19f","user":{"login":"phillip-hopper","id":5262964,"avatar_url":"https://avatars.githubusercontent.com/u/5262964?v=3","gravatar_id":"","url":"https://api.github.com/users/phillip-hopper","html_url":"https://github.com/phillip-hopper","followers_url":"https://api.github.com/users/phillip-hopper/followers","following_url":"https://api.github.com/users/phillip-hopper/following{/other_user}","gists_url":"https://api.github.com/users/phillip-hopper/gists{/gist_id}","starred_url":"https://api.github.com/users/phillip-hopper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillip-hopper/subscriptions","organizations_url":"https://api.github.com/users/phillip-hopper/orgs","repos_url":"https://api.github.com/users/phillip-hopper/repos","events_url":"https://api.github.com/users/phillip-hopper/events{/privacy}","received_events_url":"https://api.github.com/users/phillip-hopper/received_events","type":"User","site_admin":false},"body":"@ethantkoenig I prefer to have the template as a separate file. The major benefit is being able to easily validate the html at design time. This takes advantage of some of the major benefits offered by modern IDE's like IntelliJ.","created_at":"2016-09-01T12:18:23Z","updated_at":"2016-09-01T12:18:23Z","html_url":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5#discussion_r77162281","pull_request_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/comments/77162281"},"html":{"href":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5#discussion_r77162281"},"pull_request":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5","id":83202309,"html_url":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5","diff_url":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5.diff","patch_url":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5.patch","issue_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/5","number":5,"state":"open","locked":false,"title":"Converts Phil's tranform.py to a lambda convert function for apex","user":{"login":"richmahn","id":2839925,"avatar_url":"https://avatars.githubusercontent.com/u/2839925?v=3","gravatar_id":"","url":"https://api.github.com/users/richmahn","html_url":"https://github.com/richmahn","followers_url":"https://api.github.com/users/richmahn/followers","following_url":"https://api.github.com/users/richmahn/following{/other_user}","gists_url":"https://api.github.com/users/richmahn/gists{/gist_id}","starred_url":"https://api.github.com/users/richmahn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richmahn/subscriptions","organizations_url":"https://api.github.com/users/richmahn/orgs","repos_url":"https://api.github.com/users/richmahn/repos","events_url":"https://api.github.com/users/richmahn/events{/privacy}","received_events_url":"https://api.github.com/users/richmahn/received_events","type":"User","site_admin":false},"body":"Lambda-fied and Apex-ified this repo. Will be able to convert more than just obs in the future.\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/unfoldingword-dev/tx-md2html/5)\n<!-- Reviewable:end -->\n","created_at":"2016-08-30T03:17:00Z","updated_at":"2016-09-01T12:18:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ae5b267228eb75e495b4237fe5b1ce32fead1832","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5/commits","review_comments_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5/comments","review_comment_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/comments{/number}","comments_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/5/comments","statuses_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/statuses/6dfaf2ff86ffafb2e67785df9b429ba8039aa19f","head":{"label":"richmahn:master","ref":"master","sha":"6dfaf2ff86ffafb2e67785df9b429ba8039aa19f","user":{"login":"richmahn","id":2839925,"avatar_url":"https://avatars.githubusercontent.com/u/2839925?v=3","gravatar_id":"","url":"https://api.github.com/users/richmahn","html_url":"https://github.com/richmahn","followers_url":"https://api.github.com/users/richmahn/followers","following_url":"https://api.github.com/users/richmahn/following{/other_user}","gists_url":"https://api.github.com/users/richmahn/gists{/gist_id}","starred_url":"https://api.github.com/users/richmahn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richmahn/subscriptions","organizations_url":"https://api.github.com/users/richmahn/orgs","repos_url":"https://api.github.com/users/richmahn/repos","events_url":"https://api.github.com/users/richmahn/events{/privacy}","received_events_url":"https://api.github.com/users/richmahn/received_events","type":"User","site_admin":false},"repo":{"id":66586077,"name":"tx-md2html","full_name":"richmahn/tx-md2html","owner":{"login":"richmahn","id":2839925,"avatar_url":"https://avatars.githubusercontent.com/u/2839925?v=3","gravatar_id":"","url":"https://api.github.com/users/richmahn","html_url":"https://github.com/richmahn","followers_url":"https://api.github.com/users/richmahn/followers","following_url":"https://api.github.com/users/richmahn/following{/other_user}","gists_url":"https://api.github.com/users/richmahn/gists{/gist_id}","starred_url":"https://api.github.com/users/richmahn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richmahn/subscriptions","organizations_url":"https://api.github.com/users/richmahn/orgs","repos_url":"https://api.github.com/users/richmahn/repos","events_url":"https://api.github.com/users/richmahn/events{/privacy}","received_events_url":"https://api.github.com/users/richmahn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/richmahn/tx-md2html","description":"Markdown to HTML tX Conversion Module","fork":true,"url":"https://api.github.com/repos/richmahn/tx-md2html","forks_url":"https://api.github.com/repos/richmahn/tx-md2html/forks","keys_url":"https://api.github.com/repos/richmahn/tx-md2html/keys{/key_id}","collaborators_url":"https://api.github.com/repos/richmahn/tx-md2html/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/richmahn/tx-md2html/teams","hooks_url":"https://api.github.com/repos/richmahn/tx-md2html/hooks","issue_events_url":"https://api.github.com/repos/richmahn/tx-md2html/issues/events{/number}","events_url":"https://api.github.com/repos/richmahn/tx-md2html/events","assignees_url":"https://api.github.com/repos/richmahn/tx-md2html/assignees{/user}","branches_url":"https://api.github.com/repos/richmahn/tx-md2html/branches{/branch}","tags_url":"https://api.github.com/repos/richmahn/tx-md2html/tags","blobs_url":"https://api.github.com/repos/richmahn/tx-md2html/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/richmahn/tx-md2html/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/richmahn/tx-md2html/git/refs{/sha}","trees_url":"https://api.github.com/repos/richmahn/tx-md2html/git/trees{/sha}","statuses_url":"https://api.github.com/repos/richmahn/tx-md2html/statuses/{sha}","languages_url":"https://api.github.com/repos/richmahn/tx-md2html/languages","stargazers_url":"https://api.github.com/repos/richmahn/tx-md2html/stargazers","contributors_url":"https://api.github.com/repos/richmahn/tx-md2html/contributors","subscribers_url":"https://api.github.com/repos/richmahn/tx-md2html/subscribers","subscription_url":"https://api.github.com/repos/richmahn/tx-md2html/subscription","commits_url":"https://api.github.com/repos/richmahn/tx-md2html/commits{/sha}","git_commits_url":"https://api.github.com/repos/richmahn/tx-md2html/git/commits{/sha}","comments_url":"https://api.github.com/repos/richmahn/tx-md2html/comments{/number}","issue_comment_url":"https://api.github.com/repos/richmahn/tx-md2html/issues/comments{/number}","contents_url":"https://api.github.com/repos/richmahn/tx-md2html/contents/{+path}","compare_url":"https://api.github.com/repos/richmahn/tx-md2html/compare/{base}...{head}","merges_url":"https://api.github.com/repos/richmahn/tx-md2html/merges","archive_url":"https://api.github.com/repos/richmahn/tx-md2html/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/richmahn/tx-md2html/downloads","issues_url":"https://api.github.com/repos/richmahn/tx-md2html/issues{/number}","pulls_url":"https://api.github.com/repos/richmahn/tx-md2html/pulls{/number}","milestones_url":"https://api.github.com/repos/richmahn/tx-md2html/milestones{/number}","notifications_url":"https://api.github.com/repos/richmahn/tx-md2html/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/richmahn/tx-md2html/labels{/name}","releases_url":"https://api.github.com/repos/richmahn/tx-md2html/releases{/id}","deployments_url":"https://api.github.com/repos/richmahn/tx-md2html/deployments","created_at":"2016-08-25T19:16:21Z","updated_at":"2016-08-28T18:57:28Z","pushed_at":"2016-08-31T14:56:21Z","git_url":"git://github.com/richmahn/tx-md2html.git","ssh_url":"git@github.com:richmahn/tx-md2html.git","clone_url":"https://github.com/richmahn/tx-md2html.git","svn_url":"https://github.com/richmahn/tx-md2html","homepage":null,"size":11,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"unfoldingWord-dev:master","ref":"master","sha":"d3869a16c5722add32589649c5e50fdb30e5d01b","user":{"login":"unfoldingWord-dev","id":11397506,"avatar_url":"https://avatars.githubusercontent.com/u/11397506?v=3","gravatar_id":"","url":"https://api.github.com/users/unfoldingWord-dev","html_url":"https://github.com/unfoldingWord-dev","followers_url":"https://api.github.com/users/unfoldingWord-dev/followers","following_url":"https://api.github.com/users/unfoldingWord-dev/following{/other_user}","gists_url":"https://api.github.com/users/unfoldingWord-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/unfoldingWord-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unfoldingWord-dev/subscriptions","organizations_url":"https://api.github.com/users/unfoldingWord-dev/orgs","repos_url":"https://api.github.com/users/unfoldingWord-dev/repos","events_url":"https://api.github.com/users/unfoldingWord-dev/events{/privacy}","received_events_url":"https://api.github.com/users/unfoldingWord-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":64434746,"name":"tx-md2html","full_name":"unfoldingWord-dev/tx-md2html","owner":{"login":"unfoldingWord-dev","id":11397506,"avatar_url":"https://avatars.githubusercontent.com/u/11397506?v=3","gravatar_id":"","url":"https://api.github.com/users/unfoldingWord-dev","html_url":"https://github.com/unfoldingWord-dev","followers_url":"https://api.github.com/users/unfoldingWord-dev/followers","following_url":"https://api.github.com/users/unfoldingWord-dev/following{/other_user}","gists_url":"https://api.github.com/users/unfoldingWord-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/unfoldingWord-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unfoldingWord-dev/subscriptions","organizations_url":"https://api.github.com/users/unfoldingWord-dev/orgs","repos_url":"https://api.github.com/users/unfoldingWord-dev/repos","events_url":"https://api.github.com/users/unfoldingWord-dev/events{/privacy}","received_events_url":"https://api.github.com/users/unfoldingWord-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/unfoldingWord-dev/tx-md2html","description":"Markdown to HTML tX Conversion Module","fork":false,"url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html","forks_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/forks","keys_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/keys{/key_id}","collaborators_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/teams","hooks_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/hooks","issue_events_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/events{/number}","events_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/events","assignees_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/assignees{/user}","branches_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/branches{/branch}","tags_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/tags","blobs_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/git/refs{/sha}","trees_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/git/trees{/sha}","statuses_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/statuses/{sha}","languages_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/languages","stargazers_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/stargazers","contributors_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/contributors","subscribers_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/subscribers","subscription_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/subscription","commits_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/commits{/sha}","git_commits_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/git/commits{/sha}","comments_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/comments{/number}","issue_comment_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/comments{/number}","contents_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/contents/{+path}","compare_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/compare/{base}...{head}","merges_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/merges","archive_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/downloads","issues_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues{/number}","pulls_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls{/number}","milestones_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/milestones{/number}","notifications_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/labels{/name}","releases_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/releases{/id}","deployments_url":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/deployments","created_at":"2016-07-28T23:26:40Z","updated_at":"2016-08-08T20:26:10Z","pushed_at":"2016-08-31T14:56:25Z","git_url":"git://github.com/unfoldingWord-dev/tx-md2html.git","ssh_url":"git@github.com:unfoldingWord-dev/tx-md2html.git","clone_url":"https://github.com/unfoldingWord-dev/tx-md2html.git","svn_url":"https://github.com/unfoldingWord-dev/tx-md2html","homepage":null,"size":13,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5"},"html":{"href":"https://github.com/unfoldingWord-dev/tx-md2html/pull/5"},"issue":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/5"},"comments":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/unfoldingWord-dev/tx-md2html/statuses/6dfaf2ff86ffafb2e67785df9b429ba8039aa19f"}}}}
{"actor":{"display_login":"phillip-hopper"}}